denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
98.07k stars 5.4k forks source link

Deno compile code cache seems not working when error thrown during module loading #26976

Closed felipecrs closed 4 days ago

felipecrs commented 4 days ago

Version: Deno 2.1.0

Reproduction:

# clone pkgx
$ cd /tmp
$ git clone https://github.com/pkgxdev/pkgx
$ cd pkgx

# confirm deno is at the right version
$ deno upgrade 2.1.0

# let's cleanup the cache just in case
$ deno clean

# same as "deno task compile", but with --log-level debug
$ deno compile --lock=deno.lock --allow-all --output "$INIT_CWD/pkgx" --log-level debug ./entrypoint.ts

# cache was not supposed to work on first attempt indeed
$ ./pkgx --version 2>&1 | grep cache
DEBUG RS - denort::cache::cache_db:170 - Opening cache /home/felipecrs/.cache/deno/node_analysis_cache_v2...
DEBUG RS - denort::standalone::code_cache:56 - Failed to deserialize code cache: Cache key mismatch
DEBUG RS - denort::cache::cache_db:389 - Created parent directory for cache db.
× unexpected error unversioned developer build
│ Error: unversioned developer build
│     at default (file:///tmp/deno-compile-pkgx-cc/pkgx/src/modes/version.ts:2:9)
│     at default (file:///tmp/deno-compile-pkgx-cc/pkgx/src/app.ts:145:27)
│     at file:///tmp/deno-compile-pkgx-cc/pkgx/entrypoint.ts:59:9
╰─➤ https://github.com/pkgxdev/pkgx/issues/new

# but even on second attempt it still seems to fail
$ ./pkgx --version 2>&1 | grep cache
DEBUG RS - denort::cache::cache_db:170 - Opening cache /home/felipecrs/.cache/deno/node_analysis_cache_v2...
DEBUG RS - denort::standalone::code_cache:56 - Failed to deserialize code cache: Cache key mismatch
× unexpected error unversioned developer build
│ Error: unversioned developer build
│     at default (file:///tmp/deno-compile-pkgx-cc/pkgx/src/modes/version.ts:2:9)
│     at default (file:///tmp/deno-compile-pkgx-cc/pkgx/src/app.ts:145:27)
│     at file:///tmp/deno-compile-pkgx-cc/pkgx/entrypoint.ts:59:9
╰─➤ https://github.com/pkgxdev/pkgx/issues/new
dsherret commented 4 days ago

I think what's happening here is its using a code cache from a previous build, but ./pkgx --version 2>&1 is erroring on "unversioned developer build" before it code caches all the modules? If you have a successful run you should see it use the code cache I think.

I'll add the code cache path to the debug logs.

felipecrs commented 4 days ago

Oh ok, indeed, if I try a working command, code cache seems to be working:

❯ ./pkgx --sync 2>&1 | grep cache
DEBUG RS - denort::cache::cache_db:170 - Opening cache /home/felipecrs/.cache/deno/node_analysis_cache_v2...
DEBUG RS - denort::standalone::code_cache:45 - Loaded 216 code cache entries
dsherret commented 4 days ago

Yeah, it doesn't save the code cache if it errors during module loading. Perhaps there could be a partial save done in some cases, but I'm not sure it's worth the effort.

felipecrs commented 4 days ago

Yeah, probably not worth it. Feel free to close this issue then.