diff options
author | Luca Casonato <hello@lcas.dev> | 2024-06-13 02:29:02 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-12 16:29:02 -0700 |
commit | 6e2d8c969c9abab2e83ff6ad2345184470337c19 (patch) | |
tree | cf47308a3ce2f72ec4f15dd11070f55fd68156eb | |
parent | a7531361ef9bcc29b31ca73b68eeae707ea91f22 (diff) |
fix: don't panic when cache is not available (#24175)
Fixes #22144
-rw-r--r-- | ext/cache/lib.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/ext/cache/lib.rs b/ext/cache/lib.rs index cee5b7e56..e399b08e0 100644 --- a/ext/cache/lib.rs +++ b/ext/cache/lib.rs @@ -6,6 +6,7 @@ use std::rc::Rc; use std::sync::Arc; use async_trait::async_trait; +use deno_core::error::type_error; use deno_core::error::AnyError; use deno_core::op2; use deno_core::serde::Deserialize; @@ -205,11 +206,12 @@ where let mut state = state.borrow_mut(); if let Some(cache) = state.try_borrow::<CA>() { Ok(cache.clone()) - } else { - let create_cache = state.borrow::<CreateCache<CA>>().clone(); + } else if let Some(create_cache) = state.try_borrow::<CreateCache<CA>>() { let cache = create_cache.0(); state.put(cache); Ok(state.borrow::<CA>().clone()) + } else { + Err(type_error("CacheStorage is not available in this context.")) } } |