From 0434e041778cb3803de901b841f18b8fd8cc2a67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 29 Jun 2023 01:46:16 +0200 Subject: [PATCH] feat: add more Deno.errors classes (#19514) This commit adds following new error classes: - `Deno.errors.NotADirectory` - `Deno.errors.FilesystemLoop` - `Deno.errors.IsADirectory` - `Deno.errors.NetworkUnreachable` Closes https://github.com/denoland/deno/issues/19408 --- runtime/errors.rs | 15 ++++++++++++++- runtime/js/01_errors.js | 32 ++++++++++++++++++++++++++++++++ runtime/js/99_main.js | 4 ++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/runtime/errors.rs b/runtime/errors.rs index 5618c07ed6..e6ae14abba 100644 --- a/runtime/errors.rs +++ b/runtime/errors.rs @@ -61,7 +61,16 @@ fn get_io_error_class(error: &io::Error) -> &'static str { WouldBlock => "WouldBlock", // Non-exhaustive enum - might add new variants // in the future - _ => "Error", + kind => { + let kind_str = kind.to_string(); + match kind_str.as_str() { + "FilesystemLoop" => "FilesystemLoop", + "IsADirectory" => "IsADirectory", + "NetworkUnreachable" => "NetworkUnreachable", + "NotADirectory" => "NotADirectory", + _ => "Error", + } + } } } @@ -146,6 +155,10 @@ pub fn get_nix_error_class(error: &nix::Error) -> &'static str { nix::Error::ENOTTY => "BadResource", nix::Error::EPERM => "PermissionDenied", nix::Error::ESRCH => "NotFound", + nix::Error::ELOOP => "FilesystemLoop", + nix::Error::ENOTDIR => "NotADirectory", + nix::Error::ENETUNREACH => "NetworkUnreachable", + nix::Error::EISDIR => "IsADirectory", nix::Error::UnknownErrno => "Error", &nix::Error::ENOTSUP => unreachable!(), _ => "Error", diff --git a/runtime/js/01_errors.js b/runtime/js/01_errors.js index 8288e3ce9a..0c54f65813 100644 --- a/runtime/js/01_errors.js +++ b/runtime/js/01_errors.js @@ -131,6 +131,34 @@ class NotSupported extends Error { } } +class FilesystemLoop extends Error { + constructor(msg) { + super(msg); + this.name = "FilesystemLoop"; + } +} + +class IsADirectory extends Error { + constructor(msg) { + super(msg); + this.name = "IsADirectory"; + } +} + +class NetworkUnreachable extends Error { + constructor(msg) { + super(msg); + this.name = "NetworkUnreachable"; + } +} + +class NotADirectory extends Error { + constructor(msg) { + super(msg); + this.name = "NotADirectory"; + } +} + const errors = { NotFound, PermissionDenied, @@ -152,6 +180,10 @@ const errors = { Http, Busy, NotSupported, + FilesystemLoop, + IsADirectory, + NetworkUnreachable, + NotADirectory, }; export { errors }; diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 511368141c..0c89897017 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -251,6 +251,10 @@ core.registerErrorClass("BadResource", errors.BadResource); core.registerErrorClass("Http", errors.Http); core.registerErrorClass("Busy", errors.Busy); core.registerErrorClass("NotSupported", errors.NotSupported); +core.registerErrorClass("FilesystemLoop", errors.FilesystemLoop); +core.registerErrorClass("IsADirectory", errors.IsADirectory); +core.registerErrorClass("NetworkUnreachable", errors.NetworkUnreachable); +core.registerErrorClass("NotADirectory", errors.NotADirectory); core.registerErrorBuilder( "DOMExceptionOperationError", function DOMExceptionOperationError(msg) {