diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-07-09 12:15:03 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-09 12:15:03 -0400 |
commit | 839caf6fafdf9ca1cdec6cd9cef38296be41145f (patch) | |
tree | 691dba21b45e9c5640275304308aa5d8a5d4a7ba /ext/fs/interface.rs | |
parent | 07613a6bf26d9112d47fda9e502425395bd78105 (diff) |
refactor: use concrete error types for node resolution (#24470)
This will help clean up some of the code in the CLI because we'll be
able to tell how the resolution failed (not part of this PR).
Diffstat (limited to 'ext/fs/interface.rs')
-rw-r--r-- | ext/fs/interface.rs | 22 |
1 files changed, 3 insertions, 19 deletions
diff --git a/ext/fs/interface.rs b/ext/fs/interface.rs index 8f791f4c2..2fdfa2186 100644 --- a/ext/fs/interface.rs +++ b/ext/fs/interface.rs @@ -350,7 +350,7 @@ impl<'a> deno_config::fs::DenoConfigFs for DenoConfigFsAdapter<'a> { self .0 .read_text_file_lossy_sync(path, None) - .map_err(map_deno_fs_to_config_err) + .map_err(|err| err.into_io_error()) } fn stat_sync( @@ -365,7 +365,7 @@ impl<'a> deno_config::fs::DenoConfigFs for DenoConfigFsAdapter<'a> { is_directory: stat.is_directory, is_symlink: stat.is_symlink, }) - .map_err(map_deno_fs_to_config_err) + .map_err(|err| err.into_io_error()) } fn read_dir( @@ -375,7 +375,7 @@ impl<'a> deno_config::fs::DenoConfigFs for DenoConfigFsAdapter<'a> { self .0 .read_dir_sync(path) - .map_err(map_deno_fs_to_config_err) + .map_err(|err| err.into_io_error()) .map(|entries| { entries .into_iter() @@ -392,22 +392,6 @@ impl<'a> deno_config::fs::DenoConfigFs for DenoConfigFsAdapter<'a> { } } -fn map_deno_fs_to_config_err(fs_err: deno_io::fs::FsError) -> std::io::Error { - use deno_io::fs::FsError; - use std::io::ErrorKind; - match fs_err { - FsError::Io(io) => io, - FsError::FileBusy => std::io::Error::new(ErrorKind::Other, "file busy"), - FsError::NotSupported => { - std::io::Error::new(ErrorKind::Other, "not supported") - } - FsError::PermissionDenied(name) => std::io::Error::new( - ErrorKind::PermissionDenied, - format!("requires {}", name), - ), - } -} - // Like String::from_utf8_lossy but operates on owned values #[inline(always)] fn string_from_utf8_lossy(buf: Vec<u8>) -> String { |