1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 00:29:09 -05:00

refactor(ext/fs): use concrete error types (#26317)

This commit is contained in:
Leo Kettmeir 2024-10-18 06:38:17 -07:00 committed by Bartek Iwańczuk
parent 33aedc9de3
commit ed1b2db88b
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750
6 changed files with 425 additions and 199 deletions

13
Cargo.lock generated
View file

@ -1423,9 +1423,9 @@ dependencies = [
[[package]]
name = "deno_core"
version = "0.314.1"
version = "0.314.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fcd11ab87426c611b7170138a768dad7170c8fb66d8095b773d25e58fd254ea"
checksum = "83138917579676069b423c3eb9be3c1e579f60dc022d85f6ded4c792456255ff"
dependencies = [
"anyhow",
"bincode",
@ -1600,6 +1600,7 @@ dependencies = [
"rand",
"rayon",
"serde",
"thiserror",
"winapi",
"windows-sys 0.52.0",
]
@ -1916,9 +1917,9 @@ dependencies = [
[[package]]
name = "deno_ops"
version = "0.190.0"
version = "0.190.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a48a3e06cace18a2c49e148da067678c6af80e70757a8c3991301397cf6b9919"
checksum = "26f46d4e4f52f26c882b74a9b58810ea75252b807cf0966166ec333077cdfd85"
dependencies = [
"proc-macro-rules",
"proc-macro2",
@ -6215,9 +6216,9 @@ dependencies = [
[[package]]
name = "serde_v8"
version = "0.223.0"
version = "0.223.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c127bb9f2024433d06789b242477c808fd7f7dc4c3278576dd5bc99c4e5c75ff"
checksum = "9cf3d859dda87ee96423c01244f10af864fa6d6a9fcdc2b77e0595078ea0ea11"
dependencies = [
"num-bigint",
"serde",

View file

@ -46,7 +46,7 @@ repository = "https://github.com/denoland/deno"
[workspace.dependencies]
deno_ast = { version = "=0.42.2", features = ["transpiling"] }
deno_core = { version = "0.314.1" }
deno_core = { version = "0.314.2" }
deno_bench_util = { version = "0.167.0", path = "./bench_util" }
deno_lockfile = "=0.23.1"

View file

@ -28,6 +28,7 @@ libc.workspace = true
rand.workspace = true
rayon = "1.8.0"
serde.workspace = true
thiserror.workspace = true
[target.'cfg(unix)'.dependencies]
nix.workspace = true

View file

@ -14,6 +14,8 @@ pub use crate::interface::FileSystemRc;
pub use crate::interface::FsDirEntry;
pub use crate::interface::FsFileType;
pub use crate::interface::OpenOptions;
pub use crate::ops::FsOpsError;
pub use crate::ops::OperationError;
pub use crate::std_fs::RealFs;
pub use crate::sync::MaybeSend;
pub use crate::sync::MaybeSync;

File diff suppressed because it is too large Load diff

View file

@ -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)