summaryrefslogtreecommitdiff
path: root/ext/io
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2024-10-24 10:45:17 -0700
committerGitHub <noreply@github.com>2024-10-24 10:45:17 -0700
commitc71e020668b40666aecfdffb1dbf979abcb41958 (patch)
tree6b963905f50c17c21d9a89a5f5f7eee2fa83e808 /ext/io
parentb063cfecfe0479b1de14b8e9e06f1921ce830127 (diff)
refactor(ext/node): use concrete error types (#26419)
Diffstat (limited to 'ext/io')
-rw-r--r--ext/io/fs.rs30
1 files changed, 16 insertions, 14 deletions
diff --git a/ext/io/fs.rs b/ext/io/fs.rs
index 06fc3da09..885426520 100644
--- a/ext/io/fs.rs
+++ b/ext/io/fs.rs
@@ -1,6 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use std::borrow::Cow;
+use std::fmt::Formatter;
use std::io;
use std::rc::Rc;
use std::time::SystemTime;
@@ -21,6 +22,21 @@ pub enum FsError {
NotCapable(&'static str),
}
+impl std::fmt::Display for FsError {
+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ match self {
+ FsError::Io(err) => std::fmt::Display::fmt(err, f),
+ FsError::FileBusy => f.write_str("file busy"),
+ FsError::NotSupported => f.write_str("not supported"),
+ FsError::NotCapable(err) => {
+ f.write_str(&format!("requires {err} access"))
+ }
+ }
+ }
+}
+
+impl std::error::Error for FsError {}
+
impl FsError {
pub fn kind(&self) -> io::ErrorKind {
match self {
@@ -55,20 +71,6 @@ impl From<io::ErrorKind> for FsError {
}
}
-impl From<FsError> for deno_core::error::AnyError {
- fn from(err: FsError) -> Self {
- match err {
- FsError::Io(err) => err.into(),
- FsError::FileBusy => deno_core::error::resource_unavailable(),
- FsError::NotSupported => deno_core::error::not_supported(),
- FsError::NotCapable(err) => deno_core::error::custom_error(
- "NotCapable",
- format!("permission denied: {err}"),
- ),
- }
- }
-}
-
impl From<JoinError> for FsError {
fn from(err: JoinError) -> Self {
if err.is_cancelled() {