mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 20:38:55 +00:00
refactor(ext/fs): use concrete error types (#26317)
This commit is contained in:
parent
c77c9b2958
commit
85a99eb405
13
Cargo.lock
generated
13
Cargo.lock
generated
@ -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",
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
575
ext/fs/ops.rs
575
ext/fs/ops.rs
File diff suppressed because it is too large
Load Diff
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user