denoland/deno · error
failed to open cache db at {}
Error message
failed to open cache db at {} What it means
In the default disk mode, Deno opens a SQLite metadata database (cache_metadata.db plus WAL/SHM sidecar files) inside its cache storage directory (derived from DENO_DIR). This panic means Connection::open failed on that exact path — the directory could not be used or the database file could not be opened or created. The message includes the full path, which tells you which directory is at fault.
Source
Thrown at ext/cache/sqlite.rs:112
.as_str()
{
"disk" | "" => Mode::Disk,
"memory" => Mode::InMemory,
_ => {
log::warn!("Unknown DENO_CACHE_DB_MODE value, defaulting to disk");
Mode::Disk
}
};
let connection = if matches!(mode, Mode::InMemory) {
rusqlite::Connection::open_in_memory()
.unwrap_or_else(|_| panic!("failed to open in-memory cache db"))
} else {
create_cache_storage_dir(&cache_storage_dir)?;
let path = cache_storage_dir.join("cache_metadata.db");
let connection = rusqlite::Connection::open(&path).unwrap_or_else(|_| {
panic!("failed to open cache db at {}", path.display())
});
// Enable write-ahead-logging mode.
let initial_pragmas = "
-- enable write-ahead-logging mode
PRAGMA journal_mode=WAL;
PRAGMA synchronous=NORMAL;
PRAGMA optimize;
";
connection.execute_batch(initial_pragmas)?;
connection
};
connection.execute(
"CREATE TABLE IF NOT EXISTS cache_storage (
id INTEGER PRIMARY KEY,
cache_name TEXT NOT NULL UNIQUE
)",
(),View on GitHub (pinned to 9ad36f7a2c)
Solutions
- Check the path in the message: ensure the directory exists and is writable (`mkdir -p` + `touch` test)
- Delete the named cache_metadata.db and its -wal/-shm siblings so Deno recreates it — it is a rebuildable cache
- Fix ownership/permissions if Deno was ever run under sudo or another user
- Point DENO_DIR at a known-writable location, e.g. `DENO_DIR=$HOME/.cache/deno`
Example fix
# before — unwritable cache dir DENO_DIR=/read-only/cache deno run app.ts # after — clear a corrupt db and use a writable dir rm -f "$HOME/.cache/deno/cache_metadata.db"* DENO_DIR=$HOME/.cache/deno deno run app.ts
Defensive patterns
Strategy: fallback
Validate before calling
# verify the cache dir is usable before running deno
CACHE="${DENO_DIR:-$HOME/.cache/deno}"
mkdir -p "$CACHE" && touch "$CACHE/cache_metadata.db" && rm "$CACHE/cache_metadata.db" \
|| echo "cache dir not writable: $CACHE" Prevention
- Keep DENO_DIR on a writable filesystem owned by the same user that runs Deno
- Delete cache_metadata.db plus -wal/-shm siblings when corruption is suspected — the cache rebuilds
- Never point DENO_DIR at a symlinked or read-only volume; keep one DENO_DIR per user/container
When it happens
Trigger: DENO_DIR (or the default cache dir) resolving to a read-only location, a permission-denied directory, a full disk, or a corrupted/locked cache_metadata.db left behind by a crashed process. Note the cache dir is also rejected if it is a symlink, which surfaces as an error before this point.
Common situations: Running Deno in containers with read-only volumes; ownership mismatches after running Deno under sudo; a previous crashed process leaving a locked or corrupt db; DENO_DIR pointing somewhere unusual in CI.
Related errors
- Native addon cache directory '{}' is not private
- BenchContext::end() has already been invoked
- failed to open in-memory cache db
- You do not have write permission to {}
- '{}' is writable or readable by other users
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/8bc2328faaccde99.
Report an issue: GitHub.