From 938a8ebe347639c07042768e97969b75cc600e16 Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Sat, 12 Oct 2024 09:15:10 -0700 Subject: refactor(ext/cache): use concrete error type (#26109) --- runtime/errors.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'runtime') 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::().map(get_cache_error)) .or_else(|| { e.downcast_ref::() .map(get_broadcast_channel_error) -- cgit v1.2.3