diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-11-16 14:29:36 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-16 14:29:36 +0000 |
commit | 768c5ea2bb2a927455577a29f0761425593aea98 (patch) | |
tree | 35b51477c3dfccccf4a6d2a9f89f2d06f16aa118 /ext | |
parent | 99d5c6e423fe67f7f062296ffd38b38f92b7ab70 (diff) |
fix(ext/cache): gracefully error when cache creation failed (#26895)
Removes panic reported in https://github.com/denoland/deno/issues/26893
Diffstat (limited to 'ext')
-rw-r--r-- | ext/cache/sqlite.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/ext/cache/sqlite.rs b/ext/cache/sqlite.rs index 6efceda11..469e3e51d 100644 --- a/ext/cache/sqlite.rs +++ b/ext/cache/sqlite.rs @@ -8,6 +8,7 @@ use std::time::SystemTime; use std::time::UNIX_EPOCH; use async_trait::async_trait; +use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_core::futures::future::poll_fn; use deno_core::parking_lot::Mutex; @@ -45,7 +46,13 @@ impl SqliteBackedCache { pub fn new(cache_storage_dir: PathBuf) -> Result<Self, CacheError> { { std::fs::create_dir_all(&cache_storage_dir) - .expect("failed to create cache dir"); + .with_context(|| { + format!( + "Failed to create cache storage directory {}", + cache_storage_dir.display() + ) + }) + .map_err(CacheError::Other)?; 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()) |