summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2024-10-18 06:38:17 -0700
committerGitHub <noreply@github.com>2024-10-18 06:38:17 -0700
commit85a99eb405ef3ec5f8e478d93b2c866afbc53f95 (patch)
tree681e7c8862a2ddca6d9d8e3531b3a7d2340ff901 /runtime
parentc77c9b29581b76e00caa56f654ba4326d297f355 (diff)
refactor(ext/fs): use concrete error types (#26317)
Diffstat (limited to 'runtime')
-rw-r--r--runtime/errors.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/runtime/errors.rs b/runtime/errors.rs
index 935f62d26..25fc664a5 100644
--- a/runtime/errors.rs
+++ b/runtime/errors.rs
@@ -23,6 +23,8 @@ use deno_ffi::DlfcnError;
use deno_ffi::IRError;
use deno_ffi::ReprError;
use deno_ffi::StaticError;
+use deno_fs::FsOpsError;
+use deno_io::fs::FsError;
use deno_kv::KvCheckError;
use deno_kv::KvError;
use deno_kv::KvMutationError;
@@ -366,6 +368,34 @@ fn get_broadcast_channel_error(error: &BroadcastChannelError) -> &'static str {
}
}
+fn get_fs_error(error: &FsOpsError) -> &'static str {
+ match error {
+ FsOpsError::Io(e) => get_io_error_class(e),
+ FsOpsError::OperationError(e) => match &e.err {
+ FsError::Io(e) => get_io_error_class(e),
+ FsError::FileBusy => "Busy",
+ FsError::NotSupported => "NotSupported",
+ FsError::NotCapable(_) => "NotCapable",
+ },
+ FsOpsError::Permission(e)
+ | FsOpsError::Resource(e)
+ | FsOpsError::Other(e) => get_error_class_name(e).unwrap_or("Error"),
+ FsOpsError::InvalidUtf8(_) => "InvalidData",
+ FsOpsError::StripPrefix(_) => "Error",
+ FsOpsError::Canceled(e) => {
+ let io_err: io::Error = e.to_owned().into();
+ get_io_error_class(&io_err)
+ }
+ FsOpsError::InvalidSeekMode(_) => "TypeError",
+ FsOpsError::InvalidControlCharacter(_) => "Error",
+ FsOpsError::InvalidCharacter(_) => "Error",
+ #[cfg(windows)]
+ FsOpsError::InvalidTrailingCharacter => "Error",
+ FsOpsError::NotCapableAccess { .. } => "NotCapable",
+ FsOpsError::NotCapable(_) => "NotCapable",
+ }
+}
+
fn get_kv_error(error: &KvError) -> &'static str {
match error {
KvError::DatabaseHandler(e) | KvError::Resource(e) | KvError::Kv(e) => {
@@ -470,6 +500,7 @@ pub fn get_error_class_name(e: &AnyError) -> Option<&'static str> {
.or_else(|| e.downcast_ref::<BlobError>().map(get_web_blob_error_class))
.or_else(|| e.downcast_ref::<IRError>().map(|_| "TypeError"))
.or_else(|| e.downcast_ref::<ReprError>().map(get_ffi_repr_error_class))
+ .or_else(|| e.downcast_ref::<FsOpsError>().map(get_fs_error))
.or_else(|| {
e.downcast_ref::<DlfcnError>()
.map(get_ffi_dlfcn_error_class)