mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
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
This commit is contained in:
parent
673cdd7149
commit
0434e04177
3 changed files with 50 additions and 1 deletions
|
@ -61,9 +61,18 @@ fn get_io_error_class(error: &io::Error) -> &'static str {
|
|||
WouldBlock => "WouldBlock",
|
||||
// Non-exhaustive enum - might add new variants
|
||||
// in the future
|
||||
kind => {
|
||||
let kind_str = kind.to_string();
|
||||
match kind_str.as_str() {
|
||||
"FilesystemLoop" => "FilesystemLoop",
|
||||
"IsADirectory" => "IsADirectory",
|
||||
"NetworkUnreachable" => "NetworkUnreachable",
|
||||
"NotADirectory" => "NotADirectory",
|
||||
_ => "Error",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_module_resolution_error_class(
|
||||
_: &ModuleResolutionError,
|
||||
|
@ -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",
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue