summaryrefslogtreecommitdiff
path: root/ext/cache/lib.rs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-11-08 12:27:29 +0530
committerGitHub <noreply@github.com>2024-11-08 12:27:29 +0530
commit637b1d5508293ed02bef2f317b30bb7c1f0cbc71 (patch)
treedc241424a5f54cd8ce56c0aaa0d11f27e3a09ddf /ext/cache/lib.rs
parentbf82c6697a9cb734998ceaa3f45768c3d8bd79b7 (diff)
fix(ext/cache): don't panic when creating cache (#26780)
Diffstat (limited to 'ext/cache/lib.rs')
-rw-r--r--ext/cache/lib.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/ext/cache/lib.rs b/ext/cache/lib.rs
index b9cc5427c..524d4cea0 100644
--- a/ext/cache/lib.rs
+++ b/ext/cache/lib.rs
@@ -33,7 +33,9 @@ pub enum CacheError {
}
#[derive(Clone)]
-pub struct CreateCache<C: Cache + 'static>(pub Arc<dyn Fn() -> C>);
+pub struct CreateCache<C: Cache + 'static>(
+ pub Arc<dyn Fn() -> Result<C, CacheError>>,
+);
deno_core::extension!(deno_cache,
deps = [ deno_webidl, deno_web, deno_url, deno_fetch ],
@@ -231,7 +233,7 @@ where
if let Some(cache) = state.try_borrow::<CA>() {
Ok(cache.clone())
} else if let Some(create_cache) = state.try_borrow::<CreateCache<CA>>() {
- let cache = create_cache.0();
+ let cache = create_cache.0()?;
state.put(cache);
Ok(state.borrow::<CA>().clone())
} else {