1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 05:42:25 -05:00

fix(ext/cache): gracefully error when cache creation failed (#26895)

Removes panic reported in https://github.com/denoland/deno/issues/26893
This commit is contained in:
Bartek Iwańczuk 2024-11-16 14:29:36 +00:00 committed by GitHub
parent 99d5c6e423
commit 768c5ea2bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

9
ext/cache/sqlite.rs vendored
View file

@ -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())