diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2024-10-12 09:15:10 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-12 09:15:10 -0700 |
commit | 938a8ebe347639c07042768e97969b75cc600e16 (patch) | |
tree | be7debd0f822e14f23f66f52ed711dae2602621d /runtime | |
parent | 3df8f1650039e9453056d516744e755d6be8801b (diff) |
refactor(ext/cache): use concrete error type (#26109)
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/errors.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/runtime/errors.rs b/runtime/errors.rs index 476aae63b..59928965b 100644 --- a/runtime/errors.rs +++ b/runtime/errors.rs @@ -10,6 +10,7 @@ //! exceptions. use deno_broadcast_channel::BroadcastChannelError; +use deno_cache::CacheError; use deno_core::error::AnyError; use deno_core::serde_json; use deno_core::url; @@ -154,6 +155,18 @@ pub fn get_nix_error_class(error: &nix::Error) -> &'static str { } } +pub fn get_cache_error(error: &CacheError) -> &'static str { + match error { + CacheError::Sqlite(_) => "Error", + CacheError::JoinError(_) => "Error", + CacheError::Resource(err) => { + deno_core::error::get_custom_error_class(err).unwrap_or("Error") + } + CacheError::Other(e) => get_error_class_name(e).unwrap_or("Error"), + CacheError::Io(err) => get_io_error_class(err), + } +} + fn get_broadcast_channel_error(error: &BroadcastChannelError) -> &'static str { match error { BroadcastChannelError::Resource(err) => { @@ -173,6 +186,7 @@ pub fn get_error_class_name(e: &AnyError) -> Option<&'static str> { .or_else(|| deno_web::get_error_class_name(e)) .or_else(|| deno_webstorage::get_not_supported_error_class_name(e)) .or_else(|| deno_websocket::get_network_error_class_name(e)) + .or_else(|| e.downcast_ref::<CacheError>().map(get_cache_error)) .or_else(|| { e.downcast_ref::<BroadcastChannelError>() .map(get_broadcast_channel_error) |