From 839caf6fafdf9ca1cdec6cd9cef38296be41145f Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 9 Jul 2024 12:15:03 -0400 Subject: 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). --- ext/fs/interface.rs | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) (limited to 'ext/fs/interface.rs') 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) -> String { -- cgit v1.2.3