Skip to content

Commit

Permalink
fix: don't panic when cache is not available (denoland#24175)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato committed Jun 12, 2024
1 parent a753136 commit 6e2d8c9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ext/cache/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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."))
}
}

Expand Down

0 comments on commit 6e2d8c9

Please sign in to comment.