From 768c5ea2bb2a927455577a29f0761425593aea98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 16 Nov 2024 14:29:36 +0000 Subject: [PATCH] fix(ext/cache): gracefully error when cache creation failed (#26895) Removes panic reported in https://github.com/denoland/deno/issues/26893 --- ext/cache/sqlite.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ext/cache/sqlite.rs b/ext/cache/sqlite.rs index 6efceda11e..469e3e51d6 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 { { 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())