deno_runtime/
errors.rs

1// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
3//! There are many types of errors in Deno:
4//! - AnyError: a generic wrapper that can encapsulate any type of error.
5//! - JsError: a container for the error message and stack trace for exceptions
6//!   thrown in JavaScript code. We use this to pretty-print stack traces.
7//! - Diagnostic: these are errors that originate in TypeScript's compiler.
8//!   They're similar to JsError, in that they have line numbers. But
9//!   Diagnostics are compile-time type errors, whereas JsErrors are runtime
10//!   exceptions.
11
12use crate::ops::fs_events::FsEventsError;
13use crate::ops::http::HttpStartError;
14use crate::ops::os::OsError;
15use crate::ops::permissions::PermissionError;
16use crate::ops::process::CheckRunPermissionError;
17use crate::ops::process::ProcessError;
18use crate::ops::signal::SignalError;
19use crate::ops::tty::TtyError;
20use crate::ops::web_worker::SyncFetchError;
21use crate::ops::worker_host::CreateWorkerError;
22use deno_broadcast_channel::BroadcastChannelError;
23use deno_cache::CacheError;
24use deno_canvas::CanvasError;
25use deno_core::error::AnyError;
26use deno_core::serde_json;
27use deno_core::url;
28use deno_core::ModuleResolutionError;
29use deno_cron::CronError;
30use deno_crypto::DecryptError;
31use deno_crypto::EncryptError;
32use deno_crypto::ExportKeyError;
33use deno_crypto::GenerateKeyError;
34use deno_crypto::ImportKeyError;
35use deno_fetch::FetchError;
36use deno_fetch::HttpClientCreateError;
37use deno_ffi::CallError;
38use deno_ffi::CallbackError;
39use deno_ffi::DlfcnError;
40use deno_ffi::IRError;
41use deno_ffi::ReprError;
42use deno_ffi::StaticError;
43use deno_fs::FsOpsError;
44use deno_fs::FsOpsErrorKind;
45use deno_http::HttpError;
46use deno_http::HttpNextError;
47use deno_http::WebSocketUpgradeError;
48use deno_io::fs::FsError;
49use deno_kv::KvCheckError;
50use deno_kv::KvError;
51use deno_kv::KvErrorKind;
52use deno_kv::KvMutationError;
53use deno_napi::NApiError;
54use deno_net::ops::NetError;
55use deno_permissions::ChildPermissionError;
56use deno_permissions::NetDescriptorFromUrlParseError;
57use deno_permissions::PathResolveError;
58use deno_permissions::PermissionCheckError;
59use deno_permissions::RunDescriptorParseError;
60use deno_permissions::SysDescriptorParseError;
61use deno_tls::TlsError;
62use deno_web::BlobError;
63use deno_web::CompressionError;
64use deno_web::MessagePortError;
65use deno_web::StreamResourceError;
66use deno_web::WebError;
67use deno_websocket::HandshakeError;
68use deno_websocket::WebsocketError;
69use deno_webstorage::WebStorageError;
70use rustyline::error::ReadlineError;
71use std::env;
72use std::error::Error;
73use std::io;
74use std::sync::Arc;
75
76fn get_run_descriptor_parse_error(e: &RunDescriptorParseError) -> &'static str {
77  match e {
78    RunDescriptorParseError::Which(_) => "Error",
79    RunDescriptorParseError::PathResolve(e) => get_path_resolve_error(e),
80    RunDescriptorParseError::EmptyRunQuery => "Error",
81  }
82}
83
84fn get_sys_descriptor_parse_error(e: &SysDescriptorParseError) -> &'static str {
85  match e {
86    SysDescriptorParseError::InvalidKind(_) => "TypeError",
87    SysDescriptorParseError::Empty => "Error",
88  }
89}
90
91fn get_path_resolve_error(e: &PathResolveError) -> &'static str {
92  match e {
93    PathResolveError::CwdResolve(e) => get_io_error_class(e),
94    PathResolveError::EmptyPath => "Error",
95  }
96}
97
98fn get_permission_error_class(e: &PermissionError) -> &'static str {
99  match e {
100    PermissionError::InvalidPermissionName(_) => "ReferenceError",
101    PermissionError::PathResolve(e) => get_path_resolve_error(e),
102    PermissionError::NetDescriptorParse(_) => "URIError",
103    PermissionError::SysDescriptorParse(e) => get_sys_descriptor_parse_error(e),
104    PermissionError::RunDescriptorParse(e) => get_run_descriptor_parse_error(e),
105  }
106}
107
108fn get_permission_check_error_class(e: &PermissionCheckError) -> &'static str {
109  match e {
110    PermissionCheckError::PermissionDenied(_) => "NotCapable",
111    PermissionCheckError::InvalidFilePath(_) => "URIError",
112    PermissionCheckError::NetDescriptorForUrlParse(e) => match e {
113      NetDescriptorFromUrlParseError::MissingHost(_) => "TypeError",
114      NetDescriptorFromUrlParseError::Host(_) => "URIError",
115    },
116    PermissionCheckError::SysDescriptorParse(e) => {
117      get_sys_descriptor_parse_error(e)
118    }
119    PermissionCheckError::PathResolve(e) => get_path_resolve_error(e),
120    PermissionCheckError::HostParse(_) => "URIError",
121  }
122}
123
124fn get_dlopen_error_class(error: &dlopen2::Error) -> &'static str {
125  use dlopen2::Error::*;
126  match error {
127    NullCharacter(_) => "InvalidData",
128    OpeningLibraryError(ref e) => get_io_error_class(e),
129    SymbolGettingError(ref e) => get_io_error_class(e),
130    AddrNotMatchingDll(ref e) => get_io_error_class(e),
131    NullSymbol => "NotFound",
132  }
133}
134
135fn get_env_var_error_class(error: &env::VarError) -> &'static str {
136  use env::VarError::*;
137  match error {
138    NotPresent => "NotFound",
139    NotUnicode(..) => "InvalidData",
140  }
141}
142
143fn get_io_error_class(error: &io::Error) -> &'static str {
144  use io::ErrorKind::*;
145  match error.kind() {
146    NotFound => "NotFound",
147    PermissionDenied => "PermissionDenied",
148    ConnectionRefused => "ConnectionRefused",
149    ConnectionReset => "ConnectionReset",
150    ConnectionAborted => "ConnectionAborted",
151    NotConnected => "NotConnected",
152    AddrInUse => "AddrInUse",
153    AddrNotAvailable => "AddrNotAvailable",
154    BrokenPipe => "BrokenPipe",
155    AlreadyExists => "AlreadyExists",
156    InvalidInput => "TypeError",
157    InvalidData => "InvalidData",
158    TimedOut => "TimedOut",
159    Interrupted => "Interrupted",
160    WriteZero => "WriteZero",
161    UnexpectedEof => "UnexpectedEof",
162    Other => "Error",
163    WouldBlock => "WouldBlock",
164    // Non-exhaustive enum - might add new variants
165    // in the future
166    kind => {
167      let kind_str = kind.to_string();
168      match kind_str.as_str() {
169        "FilesystemLoop" => "FilesystemLoop",
170        "IsADirectory" => "IsADirectory",
171        "NetworkUnreachable" => "NetworkUnreachable",
172        "NotADirectory" => "NotADirectory",
173        _ => "Error",
174      }
175    }
176  }
177}
178
179fn get_module_resolution_error_class(
180  _: &ModuleResolutionError,
181) -> &'static str {
182  "URIError"
183}
184
185fn get_notify_error_class(error: &notify::Error) -> &'static str {
186  use notify::ErrorKind::*;
187  match error.kind {
188    Generic(_) => "Error",
189    Io(ref e) => get_io_error_class(e),
190    PathNotFound => "NotFound",
191    WatchNotFound => "NotFound",
192    InvalidConfig(_) => "InvalidData",
193    MaxFilesWatch => "Error",
194  }
195}
196
197fn get_regex_error_class(error: &regex::Error) -> &'static str {
198  use regex::Error::*;
199  match error {
200    Syntax(_) => "SyntaxError",
201    CompiledTooBig(_) => "RangeError",
202    _ => "Error",
203  }
204}
205
206fn get_serde_json_error_class(
207  error: &serde_json::error::Error,
208) -> &'static str {
209  use deno_core::serde_json::error::*;
210  match error.classify() {
211    Category::Io => error
212      .source()
213      .and_then(|e| e.downcast_ref::<io::Error>())
214      .map(get_io_error_class)
215      .unwrap(),
216    Category::Syntax => "SyntaxError",
217    Category::Data => "InvalidData",
218    Category::Eof => "UnexpectedEof",
219  }
220}
221
222fn get_url_parse_error_class(_error: &url::ParseError) -> &'static str {
223  "URIError"
224}
225
226fn get_hyper_error_class(_error: &hyper::Error) -> &'static str {
227  "Http"
228}
229
230fn get_hyper_util_error_class(
231  _error: &hyper_util::client::legacy::Error,
232) -> &'static str {
233  "Http"
234}
235
236fn get_hyper_v014_error_class(_error: &hyper_v014::Error) -> &'static str {
237  "Http"
238}
239
240#[cfg(unix)]
241pub fn get_nix_error_class(error: &nix::Error) -> &'static str {
242  match error {
243    nix::Error::ECHILD => "NotFound",
244    nix::Error::EINVAL => "TypeError",
245    nix::Error::ENOENT => "NotFound",
246    nix::Error::ENOTTY => "BadResource",
247    nix::Error::EPERM => "PermissionDenied",
248    nix::Error::ESRCH => "NotFound",
249    nix::Error::ELOOP => "FilesystemLoop",
250    nix::Error::ENOTDIR => "NotADirectory",
251    nix::Error::ENETUNREACH => "NetworkUnreachable",
252    nix::Error::EISDIR => "IsADirectory",
253    nix::Error::UnknownErrno => "Error",
254    &nix::Error::ENOTSUP => unreachable!(),
255    _ => "Error",
256  }
257}
258
259fn get_webgpu_error_class(e: &deno_webgpu::InitError) -> &'static str {
260  match e {
261    deno_webgpu::InitError::Resource(e) => {
262      get_error_class_name(e).unwrap_or("Error")
263    }
264    deno_webgpu::InitError::InvalidAdapter(_) => "Error",
265    deno_webgpu::InitError::RequestDevice(_) => "DOMExceptionOperationError",
266    deno_webgpu::InitError::InvalidDevice(_) => "Error",
267  }
268}
269
270fn get_webgpu_buffer_error_class(
271  e: &deno_webgpu::buffer::BufferError,
272) -> &'static str {
273  match e {
274    deno_webgpu::buffer::BufferError::Resource(e) => {
275      get_error_class_name(e).unwrap_or("Error")
276    }
277    deno_webgpu::buffer::BufferError::InvalidUsage => "TypeError",
278    deno_webgpu::buffer::BufferError::Access(_) => "DOMExceptionOperationError",
279  }
280}
281
282fn get_webgpu_bundle_error_class(
283  e: &deno_webgpu::bundle::BundleError,
284) -> &'static str {
285  match e {
286    deno_webgpu::bundle::BundleError::Resource(e) => {
287      get_error_class_name(e).unwrap_or("Error")
288    }
289    deno_webgpu::bundle::BundleError::InvalidSize => "TypeError",
290  }
291}
292
293fn get_webgpu_byow_error_class(
294  e: &deno_webgpu::byow::ByowError,
295) -> &'static str {
296  match e {
297    deno_webgpu::byow::ByowError::WebGPUNotInitiated => "TypeError",
298    deno_webgpu::byow::ByowError::InvalidParameters => "TypeError",
299    deno_webgpu::byow::ByowError::CreateSurface(_) => "Error",
300    deno_webgpu::byow::ByowError::InvalidSystem => "TypeError",
301    #[cfg(any(
302      target_os = "windows",
303      target_os = "linux",
304      target_os = "freebsd",
305      target_os = "openbsd"
306    ))]
307    deno_webgpu::byow::ByowError::NullWindow => "TypeError",
308    #[cfg(any(
309      target_os = "linux",
310      target_os = "freebsd",
311      target_os = "openbsd"
312    ))]
313    deno_webgpu::byow::ByowError::NullDisplay => "TypeError",
314    #[cfg(target_os = "macos")]
315    deno_webgpu::byow::ByowError::NSViewDisplay => "TypeError",
316  }
317}
318
319fn get_webgpu_render_pass_error_class(
320  e: &deno_webgpu::render_pass::RenderPassError,
321) -> &'static str {
322  match e {
323    deno_webgpu::render_pass::RenderPassError::Resource(e) => {
324      get_error_class_name(e).unwrap_or("Error")
325    }
326    deno_webgpu::render_pass::RenderPassError::InvalidSize => "TypeError",
327  }
328}
329
330fn get_webgpu_surface_error_class(
331  e: &deno_webgpu::surface::SurfaceError,
332) -> &'static str {
333  match e {
334    deno_webgpu::surface::SurfaceError::Resource(e) => {
335      get_error_class_name(e).unwrap_or("Error")
336    }
337    deno_webgpu::surface::SurfaceError::Surface(_) => "Error",
338    deno_webgpu::surface::SurfaceError::InvalidStatus => "Error",
339  }
340}
341
342fn get_crypto_decrypt_error_class(e: &DecryptError) -> &'static str {
343  match e {
344    DecryptError::General(e) => get_crypto_shared_error_class(e),
345    DecryptError::Pkcs1(_) => "Error",
346    DecryptError::Failed => "DOMExceptionOperationError",
347    DecryptError::InvalidLength => "TypeError",
348    DecryptError::InvalidCounterLength => "TypeError",
349    DecryptError::InvalidTagLength => "TypeError",
350    DecryptError::InvalidKeyOrIv => "DOMExceptionOperationError",
351    DecryptError::TooMuchData => "DOMExceptionOperationError",
352    DecryptError::InvalidIvLength => "TypeError",
353    DecryptError::Rsa(_) => "DOMExceptionOperationError",
354  }
355}
356
357fn get_crypto_encrypt_error_class(e: &EncryptError) -> &'static str {
358  match e {
359    EncryptError::General(e) => get_crypto_shared_error_class(e),
360    EncryptError::InvalidKeyOrIv => "DOMExceptionOperationError",
361    EncryptError::Failed => "DOMExceptionOperationError",
362    EncryptError::InvalidLength => "TypeError",
363    EncryptError::InvalidIvLength => "TypeError",
364    EncryptError::InvalidCounterLength => "TypeError",
365    EncryptError::TooMuchData => "DOMExceptionOperationError",
366  }
367}
368
369fn get_crypto_shared_error_class(e: &deno_crypto::SharedError) -> &'static str {
370  match e {
371    deno_crypto::SharedError::ExpectedValidPrivateKey => "TypeError",
372    deno_crypto::SharedError::ExpectedValidPublicKey => "TypeError",
373    deno_crypto::SharedError::ExpectedValidPrivateECKey => "TypeError",
374    deno_crypto::SharedError::ExpectedValidPublicECKey => "TypeError",
375    deno_crypto::SharedError::ExpectedPrivateKey => "TypeError",
376    deno_crypto::SharedError::ExpectedPublicKey => "TypeError",
377    deno_crypto::SharedError::ExpectedSecretKey => "TypeError",
378    deno_crypto::SharedError::FailedDecodePrivateKey => {
379      "DOMExceptionOperationError"
380    }
381    deno_crypto::SharedError::FailedDecodePublicKey => {
382      "DOMExceptionOperationError"
383    }
384    deno_crypto::SharedError::UnsupportedFormat => {
385      "DOMExceptionNotSupportedError"
386    }
387  }
388}
389
390fn get_crypto_ed25519_error_class(
391  e: &deno_crypto::Ed25519Error,
392) -> &'static str {
393  match e {
394    deno_crypto::Ed25519Error::FailedExport => "DOMExceptionOperationError",
395    deno_crypto::Ed25519Error::Der(_) => "Error",
396    deno_crypto::Ed25519Error::KeyRejected(_) => "Error",
397  }
398}
399
400fn get_crypto_export_key_error_class(e: &ExportKeyError) -> &'static str {
401  match e {
402    ExportKeyError::General(e) => get_crypto_shared_error_class(e),
403    ExportKeyError::Der(_) => "Error",
404    ExportKeyError::UnsupportedNamedCurve => "DOMExceptionNotSupportedError",
405  }
406}
407
408fn get_crypto_generate_key_error_class(e: &GenerateKeyError) -> &'static str {
409  match e {
410    GenerateKeyError::General(e) => get_crypto_shared_error_class(e),
411    GenerateKeyError::BadPublicExponent => "DOMExceptionOperationError",
412    GenerateKeyError::InvalidHMACKeyLength => "DOMExceptionOperationError",
413    GenerateKeyError::FailedRSAKeySerialization => "DOMExceptionOperationError",
414    GenerateKeyError::InvalidAESKeyLength => "DOMExceptionOperationError",
415    GenerateKeyError::FailedRSAKeyGeneration => "DOMExceptionOperationError",
416    GenerateKeyError::FailedECKeyGeneration => "DOMExceptionOperationError",
417    GenerateKeyError::FailedKeyGeneration => "DOMExceptionOperationError",
418  }
419}
420
421fn get_crypto_import_key_error_class(e: &ImportKeyError) -> &'static str {
422  match e {
423    ImportKeyError::General(e) => get_crypto_shared_error_class(e),
424    ImportKeyError::InvalidModulus => "DOMExceptionDataError",
425    ImportKeyError::InvalidPublicExponent => "DOMExceptionDataError",
426    ImportKeyError::InvalidPrivateExponent => "DOMExceptionDataError",
427    ImportKeyError::InvalidFirstPrimeFactor => "DOMExceptionDataError",
428    ImportKeyError::InvalidSecondPrimeFactor => "DOMExceptionDataError",
429    ImportKeyError::InvalidFirstCRTExponent => "DOMExceptionDataError",
430    ImportKeyError::InvalidSecondCRTExponent => "DOMExceptionDataError",
431    ImportKeyError::InvalidCRTCoefficient => "DOMExceptionDataError",
432    ImportKeyError::InvalidB64Coordinate => "DOMExceptionDataError",
433    ImportKeyError::InvalidRSAPublicKey => "DOMExceptionDataError",
434    ImportKeyError::InvalidRSAPrivateKey => "DOMExceptionDataError",
435    ImportKeyError::UnsupportedAlgorithm => "DOMExceptionDataError",
436    ImportKeyError::PublicKeyTooLong => "DOMExceptionDataError",
437    ImportKeyError::PrivateKeyTooLong => "DOMExceptionDataError",
438    ImportKeyError::InvalidP256ECPoint => "DOMExceptionDataError",
439    ImportKeyError::InvalidP384ECPoint => "DOMExceptionDataError",
440    ImportKeyError::InvalidP521ECPoint => "DOMExceptionDataError",
441    ImportKeyError::UnsupportedNamedCurve => "DOMExceptionDataError",
442    ImportKeyError::CurveMismatch => "DOMExceptionDataError",
443    ImportKeyError::InvalidKeyData => "DOMExceptionDataError",
444    ImportKeyError::InvalidJWKPrivateKey => "DOMExceptionDataError",
445    ImportKeyError::EllipticCurve(_) => "DOMExceptionDataError",
446    ImportKeyError::ExpectedValidPkcs8Data => "DOMExceptionDataError",
447    ImportKeyError::MalformedParameters => "DOMExceptionDataError",
448    ImportKeyError::Spki(_) => "DOMExceptionDataError",
449    ImportKeyError::InvalidP256ECSPKIData => "DOMExceptionDataError",
450    ImportKeyError::InvalidP384ECSPKIData => "DOMExceptionDataError",
451    ImportKeyError::InvalidP521ECSPKIData => "DOMExceptionDataError",
452    ImportKeyError::Der(_) => "DOMExceptionDataError",
453  }
454}
455
456fn get_crypto_x448_error_class(e: &deno_crypto::X448Error) -> &'static str {
457  match e {
458    deno_crypto::X448Error::FailedExport => "DOMExceptionOperationError",
459    deno_crypto::X448Error::Der(_) => "Error",
460  }
461}
462
463fn get_crypto_x25519_error_class(e: &deno_crypto::X25519Error) -> &'static str {
464  match e {
465    deno_crypto::X25519Error::FailedExport => "DOMExceptionOperationError",
466    deno_crypto::X25519Error::Der(_) => "Error",
467  }
468}
469
470fn get_crypto_error_class(e: &deno_crypto::Error) -> &'static str {
471  match e {
472    deno_crypto::Error::Der(_) => "Error",
473    deno_crypto::Error::JoinError(_) => "Error",
474    deno_crypto::Error::MissingArgumentHash => "TypeError",
475    deno_crypto::Error::MissingArgumentSaltLength => "TypeError",
476    deno_crypto::Error::Other(e) => get_error_class_name(e).unwrap_or("Error"),
477    deno_crypto::Error::UnsupportedAlgorithm => "TypeError",
478    deno_crypto::Error::KeyRejected(_) => "Error",
479    deno_crypto::Error::RSA(_) => "Error",
480    deno_crypto::Error::Pkcs1(_) => "Error",
481    deno_crypto::Error::Unspecified(_) => "Error",
482    deno_crypto::Error::InvalidKeyFormat => "TypeError",
483    deno_crypto::Error::MissingArgumentPublicKey => "TypeError",
484    deno_crypto::Error::P256Ecdsa(_) => "Error",
485    deno_crypto::Error::DecodePrivateKey => "TypeError",
486    deno_crypto::Error::MissingArgumentNamedCurve => "TypeError",
487    deno_crypto::Error::MissingArgumentInfo => "TypeError",
488    deno_crypto::Error::HKDFLengthTooLarge => "DOMExceptionOperationError",
489    deno_crypto::Error::General(e) => get_crypto_shared_error_class(e),
490    deno_crypto::Error::Base64Decode(_) => "Error",
491    deno_crypto::Error::DataInvalidSize => "TypeError",
492    deno_crypto::Error::InvalidKeyLength => "TypeError",
493    deno_crypto::Error::EncryptionError => "DOMExceptionOperationError",
494    deno_crypto::Error::DecryptionError => "DOMExceptionOperationError",
495    deno_crypto::Error::ArrayBufferViewLengthExceeded(_) => {
496      "DOMExceptionQuotaExceededError"
497    }
498  }
499}
500
501fn get_napi_error_class(e: &NApiError) -> &'static str {
502  match e {
503    NApiError::InvalidPath
504    | NApiError::LibLoading(_)
505    | NApiError::ModuleNotFound(_) => "TypeError",
506    NApiError::Permission(e) => get_permission_check_error_class(e),
507  }
508}
509
510fn get_web_error_class(e: &WebError) -> &'static str {
511  match e {
512    WebError::Base64Decode => "DOMExceptionInvalidCharacterError",
513    WebError::InvalidEncodingLabel(_) => "RangeError",
514    WebError::BufferTooLong => "TypeError",
515    WebError::ValueTooLarge => "RangeError",
516    WebError::BufferTooSmall => "RangeError",
517    WebError::DataInvalid => "TypeError",
518    WebError::DataError(_) => "Error",
519  }
520}
521
522fn get_web_compression_error_class(e: &CompressionError) -> &'static str {
523  match e {
524    CompressionError::UnsupportedFormat => "TypeError",
525    CompressionError::ResourceClosed => "TypeError",
526    CompressionError::IoTypeError(_) => "TypeError",
527    CompressionError::Io(e) => get_io_error_class(e),
528  }
529}
530
531fn get_web_message_port_error_class(e: &MessagePortError) -> &'static str {
532  match e {
533    MessagePortError::InvalidTransfer => "TypeError",
534    MessagePortError::NotReady => "TypeError",
535    MessagePortError::TransferSelf => "TypeError",
536    MessagePortError::Canceled(e) => {
537      let io_err: io::Error = e.to_owned().into();
538      get_io_error_class(&io_err)
539    }
540    MessagePortError::Resource(e) => get_error_class_name(e).unwrap_or("Error"),
541  }
542}
543
544fn get_web_stream_resource_error_class(
545  e: &StreamResourceError,
546) -> &'static str {
547  match e {
548    StreamResourceError::Canceled(e) => {
549      let io_err: io::Error = e.to_owned().into();
550      get_io_error_class(&io_err)
551    }
552    StreamResourceError::Js(_) => "TypeError",
553  }
554}
555
556fn get_web_blob_error_class(e: &BlobError) -> &'static str {
557  match e {
558    BlobError::BlobPartNotFound => "TypeError",
559    BlobError::SizeLargerThanBlobPart => "TypeError",
560    BlobError::BlobURLsNotSupported => "TypeError",
561    BlobError::Url(_) => "Error",
562  }
563}
564
565fn get_ffi_repr_error_class(e: &ReprError) -> &'static str {
566  match e {
567    ReprError::InvalidOffset => "TypeError",
568    ReprError::InvalidArrayBuffer => "TypeError",
569    ReprError::DestinationLengthTooShort => "RangeError",
570    ReprError::InvalidCString => "TypeError",
571    ReprError::CStringTooLong => "TypeError",
572    ReprError::InvalidBool => "TypeError",
573    ReprError::InvalidU8 => "TypeError",
574    ReprError::InvalidI8 => "TypeError",
575    ReprError::InvalidU16 => "TypeError",
576    ReprError::InvalidI16 => "TypeError",
577    ReprError::InvalidU32 => "TypeError",
578    ReprError::InvalidI32 => "TypeError",
579    ReprError::InvalidU64 => "TypeError",
580    ReprError::InvalidI64 => "TypeError",
581    ReprError::InvalidF32 => "TypeError",
582    ReprError::InvalidF64 => "TypeError",
583    ReprError::InvalidPointer => "TypeError",
584    ReprError::Permission(e) => get_permission_check_error_class(e),
585  }
586}
587
588fn get_ffi_dlfcn_error_class(e: &DlfcnError) -> &'static str {
589  match e {
590    DlfcnError::RegisterSymbol { .. } => "Error",
591    DlfcnError::Dlopen(_) => "Error",
592    DlfcnError::Permission(e) => get_permission_check_error_class(e),
593    DlfcnError::Other(e) => get_error_class_name(e).unwrap_or("Error"),
594  }
595}
596
597fn get_ffi_static_error_class(e: &StaticError) -> &'static str {
598  match e {
599    StaticError::Dlfcn(e) => get_ffi_dlfcn_error_class(e),
600    StaticError::InvalidTypeVoid => "TypeError",
601    StaticError::InvalidTypeStruct => "TypeError",
602    StaticError::Resource(e) => get_error_class_name(e).unwrap_or("Error"),
603  }
604}
605
606fn get_ffi_callback_error_class(e: &CallbackError) -> &'static str {
607  match e {
608    CallbackError::Resource(e) => get_error_class_name(e).unwrap_or("Error"),
609    CallbackError::Other(e) => get_error_class_name(e).unwrap_or("Error"),
610    CallbackError::Permission(e) => get_permission_check_error_class(e),
611  }
612}
613
614fn get_ffi_call_error_class(e: &CallError) -> &'static str {
615  match e {
616    CallError::IR(_) => "TypeError",
617    CallError::NonblockingCallFailure(_) => "Error",
618    CallError::InvalidSymbol(_) => "TypeError",
619    CallError::Permission(e) => get_permission_check_error_class(e),
620    CallError::Callback(e) => get_ffi_callback_error_class(e),
621    CallError::Resource(e) => get_error_class_name(e).unwrap_or("Error"),
622  }
623}
624
625fn get_webstorage_class_name(e: &WebStorageError) -> &'static str {
626  match e {
627    WebStorageError::ContextNotSupported => "DOMExceptionNotSupportedError",
628    WebStorageError::Sqlite(_) => "Error",
629    WebStorageError::Io(e) => get_io_error_class(e),
630    WebStorageError::StorageExceeded => "DOMExceptionQuotaExceededError",
631  }
632}
633
634fn get_tls_error_class(e: &TlsError) -> &'static str {
635  match e {
636    TlsError::Rustls(_) => "Error",
637    TlsError::UnableAddPemFileToCert(e) => get_io_error_class(e),
638    TlsError::CertInvalid
639    | TlsError::CertsNotFound
640    | TlsError::KeysNotFound
641    | TlsError::KeyDecode => "InvalidData",
642  }
643}
644
645pub fn get_cron_error_class(e: &CronError) -> &'static str {
646  match e {
647    CronError::Resource(e) => {
648      deno_core::error::get_custom_error_class(e).unwrap_or("Error")
649    }
650    CronError::NameExceeded(_) => "TypeError",
651    CronError::NameInvalid => "TypeError",
652    CronError::AlreadyExists => "TypeError",
653    CronError::TooManyCrons => "TypeError",
654    CronError::InvalidCron => "TypeError",
655    CronError::InvalidBackoff => "TypeError",
656    CronError::AcquireError(_) => "Error",
657    CronError::Other(e) => get_error_class_name(e).unwrap_or("Error"),
658  }
659}
660
661fn get_canvas_error(e: &CanvasError) -> &'static str {
662  match e {
663    CanvasError::UnsupportedColorType(_) => "TypeError",
664    CanvasError::Image(_) => "Error",
665  }
666}
667
668pub fn get_cache_error(error: &CacheError) -> &'static str {
669  match error {
670    CacheError::Sqlite(_) => "Error",
671    CacheError::JoinError(_) => "Error",
672    CacheError::Resource(err) => {
673      deno_core::error::get_custom_error_class(err).unwrap_or("Error")
674    }
675    CacheError::Other(e) => get_error_class_name(e).unwrap_or("Error"),
676    CacheError::Io(err) => get_io_error_class(err),
677  }
678}
679
680fn get_broadcast_channel_error(error: &BroadcastChannelError) -> &'static str {
681  match error {
682    BroadcastChannelError::Resource(err) => {
683      deno_core::error::get_custom_error_class(err).unwrap()
684    }
685    BroadcastChannelError::MPSCSendError(_) => "Error",
686    BroadcastChannelError::BroadcastSendError(_) => "Error",
687    BroadcastChannelError::Other(err) => {
688      get_error_class_name(err).unwrap_or("Error")
689    }
690  }
691}
692
693fn get_fetch_error(error: &FetchError) -> &'static str {
694  match error {
695    FetchError::Resource(e) => get_error_class_name(e).unwrap_or("Error"),
696    FetchError::Permission(e) => get_permission_check_error_class(e),
697    FetchError::NetworkError => "TypeError",
698    FetchError::FsNotGet(_) => "TypeError",
699    FetchError::InvalidUrl(_) => "TypeError",
700    FetchError::InvalidHeaderName(_) => "TypeError",
701    FetchError::InvalidHeaderValue(_) => "TypeError",
702    FetchError::DataUrl(_) => "TypeError",
703    FetchError::Base64(_) => "TypeError",
704    FetchError::BlobNotFound => "TypeError",
705    FetchError::SchemeNotSupported(_) => "TypeError",
706    FetchError::RequestCanceled => "TypeError",
707    FetchError::Http(_) => "Error",
708    FetchError::ClientCreate(e) => get_http_client_create_error(e),
709    FetchError::Url(e) => get_url_parse_error_class(e),
710    FetchError::Method(_) => "TypeError",
711    FetchError::ClientSend(_) => "TypeError",
712    FetchError::RequestBuilderHook(_) => "TypeError",
713    FetchError::Io(e) => get_io_error_class(e),
714    FetchError::Hyper(e) => get_hyper_error_class(e),
715  }
716}
717
718fn get_http_client_create_error(error: &HttpClientCreateError) -> &'static str {
719  match error {
720    HttpClientCreateError::Tls(_) => "TypeError",
721    HttpClientCreateError::InvalidUserAgent(_) => "TypeError",
722    HttpClientCreateError::InvalidProxyUrl => "TypeError",
723    HttpClientCreateError::HttpVersionSelectionInvalid => "TypeError",
724    HttpClientCreateError::RootCertStore(_) => "TypeError",
725  }
726}
727
728fn get_websocket_error(error: &WebsocketError) -> &'static str {
729  match error {
730    WebsocketError::Resource(e) => get_error_class_name(e).unwrap_or("Error"),
731    WebsocketError::Permission(e) => get_permission_check_error_class(e),
732    WebsocketError::Url(e) => get_url_parse_error_class(e),
733    WebsocketError::Io(e) => get_io_error_class(e),
734    WebsocketError::WebSocket(_) => "TypeError",
735    WebsocketError::ConnectionFailed(_) => "DOMExceptionNetworkError",
736    WebsocketError::Uri(_) => "Error",
737    WebsocketError::Canceled(e) => {
738      let io_err: io::Error = e.to_owned().into();
739      get_io_error_class(&io_err)
740    }
741  }
742}
743
744fn get_websocket_handshake_error(error: &HandshakeError) -> &'static str {
745  match error {
746    HandshakeError::RootStoreError(e) => {
747      get_error_class_name(e).unwrap_or("Error")
748    }
749    HandshakeError::Tls(e) => get_tls_error_class(e),
750    HandshakeError::MissingPath => "TypeError",
751    HandshakeError::Http(_) => "Error",
752    HandshakeError::InvalidHostname(_) => "TypeError",
753    HandshakeError::Io(e) => get_io_error_class(e),
754    HandshakeError::Rustls(_) => "Error",
755    HandshakeError::H2(_) => "Error",
756    HandshakeError::NoH2Alpn => "Error",
757    HandshakeError::InvalidStatusCode(_) => "Error",
758    HandshakeError::WebSocket(_) => "TypeError",
759    HandshakeError::HeaderName(_) => "TypeError",
760    HandshakeError::HeaderValue(_) => "TypeError",
761  }
762}
763
764fn get_fs_ops_error(error: &FsOpsError) -> &'static str {
765  use FsOpsErrorKind::*;
766  match error.as_kind() {
767    Io(e) => get_io_error_class(e),
768    OperationError(e) => get_fs_error(&e.err),
769    Permission(e) => get_permission_check_error_class(e),
770    Resource(e) | Other(e) => get_error_class_name(e).unwrap_or("Error"),
771    InvalidUtf8(_) => "InvalidData",
772    StripPrefix(_) => "Error",
773    Canceled(e) => {
774      let io_err: io::Error = e.to_owned().into();
775      get_io_error_class(&io_err)
776    }
777    InvalidSeekMode(_) => "TypeError",
778    InvalidControlCharacter(_) => "Error",
779    InvalidCharacter(_) => "Error",
780    #[cfg(windows)]
781    InvalidTrailingCharacter => "Error",
782    NotCapableAccess { .. } => "NotCapable",
783    NotCapable(_) => "NotCapable",
784  }
785}
786
787fn get_kv_error(error: &KvError) -> &'static str {
788  use KvErrorKind::*;
789  match error.as_kind() {
790    DatabaseHandler(e) | Resource(e) | Kv(e) => {
791      get_error_class_name(e).unwrap_or("Error")
792    }
793    TooManyRanges(_) => "TypeError",
794    TooManyEntries(_) => "TypeError",
795    TooManyChecks(_) => "TypeError",
796    TooManyMutations(_) => "TypeError",
797    TooManyKeys(_) => "TypeError",
798    InvalidLimit => "TypeError",
799    InvalidBoundaryKey => "TypeError",
800    KeyTooLargeToRead(_) => "TypeError",
801    KeyTooLargeToWrite(_) => "TypeError",
802    TotalMutationTooLarge(_) => "TypeError",
803    TotalKeyTooLarge(_) => "TypeError",
804    Io(e) => get_io_error_class(e),
805    QueueMessageNotFound => "TypeError",
806    StartKeyNotInKeyspace => "TypeError",
807    EndKeyNotInKeyspace => "TypeError",
808    StartKeyGreaterThanEndKey => "TypeError",
809    InvalidCheck(e) => match e {
810      KvCheckError::InvalidVersionstamp => "TypeError",
811      KvCheckError::Io(e) => get_io_error_class(e),
812    },
813    InvalidMutation(e) => match e {
814      KvMutationError::BigInt(_) => "Error",
815      KvMutationError::Io(e) => get_io_error_class(e),
816      KvMutationError::InvalidMutationWithValue(_) => "TypeError",
817      KvMutationError::InvalidMutationWithoutValue(_) => "TypeError",
818    },
819    InvalidEnqueue(e) => get_io_error_class(e),
820    EmptyKey => "TypeError",
821    ValueTooLarge(_) => "TypeError",
822    EnqueuePayloadTooLarge(_) => "TypeError",
823    InvalidCursor => "TypeError",
824    CursorOutOfBounds => "TypeError",
825    InvalidRange => "TypeError",
826  }
827}
828
829fn get_net_error(error: &NetError) -> &'static str {
830  match error {
831    NetError::ListenerClosed => "BadResource",
832    NetError::ListenerBusy => "Busy",
833    NetError::SocketClosed => "BadResource",
834    NetError::SocketClosedNotConnected => "NotConnected",
835    NetError::SocketBusy => "Busy",
836    NetError::Io(e) => get_io_error_class(e),
837    NetError::AcceptTaskOngoing => "Busy",
838    NetError::RootCertStore(e) | NetError::Resource(e) => {
839      get_error_class_name(e).unwrap_or("Error")
840    }
841    NetError::Permission(e) => get_permission_check_error_class(e),
842    NetError::NoResolvedAddress => "Error",
843    NetError::AddrParse(_) => "Error",
844    NetError::Map(e) => get_net_map_error(e),
845    NetError::Canceled(e) => {
846      let io_err: io::Error = e.to_owned().into();
847      get_io_error_class(&io_err)
848    }
849    NetError::DnsNotFound(_) => "NotFound",
850    NetError::DnsNotConnected(_) => "NotConnected",
851    NetError::DnsTimedOut(_) => "TimedOut",
852    NetError::Dns(_) => "Error",
853    NetError::UnsupportedRecordType => "NotSupported",
854    NetError::InvalidUtf8(_) => "InvalidData",
855    NetError::UnexpectedKeyType => "Error",
856    NetError::InvalidHostname(_) => "TypeError",
857    NetError::TcpStreamBusy => "Busy",
858    NetError::Rustls(_) => "Error",
859    NetError::Tls(e) => get_tls_error_class(e),
860    NetError::ListenTlsRequiresKey => "InvalidData",
861    NetError::Reunite(_) => "Error",
862  }
863}
864
865fn get_net_map_error(error: &deno_net::io::MapError) -> &'static str {
866  match error {
867    deno_net::io::MapError::Io(e) => get_io_error_class(e),
868    deno_net::io::MapError::NoResources => "Error",
869  }
870}
871
872fn get_child_permission_error(e: &ChildPermissionError) -> &'static str {
873  match e {
874    ChildPermissionError::Escalation => "NotCapable",
875    ChildPermissionError::PathResolve(e) => get_path_resolve_error(e),
876    ChildPermissionError::NetDescriptorParse(_) => "URIError",
877    ChildPermissionError::EnvDescriptorParse(_) => "Error",
878    ChildPermissionError::SysDescriptorParse(e) => {
879      get_sys_descriptor_parse_error(e)
880    }
881    ChildPermissionError::RunDescriptorParse(e) => {
882      get_run_descriptor_parse_error(e)
883    }
884  }
885}
886
887fn get_create_worker_error(error: &CreateWorkerError) -> &'static str {
888  match error {
889    CreateWorkerError::ClassicWorkers => "DOMExceptionNotSupportedError",
890    CreateWorkerError::Permission(e) => get_child_permission_error(e),
891    CreateWorkerError::ModuleResolution(e) => {
892      get_module_resolution_error_class(e)
893    }
894    CreateWorkerError::Io(e) => get_io_error_class(e),
895    CreateWorkerError::MessagePort(e) => get_web_message_port_error_class(e),
896  }
897}
898
899fn get_tty_error(error: &TtyError) -> &'static str {
900  match error {
901    TtyError::Resource(e) | TtyError::Other(e) => {
902      get_error_class_name(e).unwrap_or("Error")
903    }
904    TtyError::Io(e) => get_io_error_class(e),
905    #[cfg(unix)]
906    TtyError::Nix(e) => get_nix_error_class(e),
907  }
908}
909
910fn get_readline_error(error: &ReadlineError) -> &'static str {
911  match error {
912    ReadlineError::Io(e) => get_io_error_class(e),
913    ReadlineError::Eof => "Error",
914    ReadlineError::Interrupted => "Error",
915    #[cfg(unix)]
916    ReadlineError::Errno(e) => get_nix_error_class(e),
917    ReadlineError::WindowResized => "Error",
918    #[cfg(windows)]
919    ReadlineError::Decode(_) => "Error",
920    #[cfg(windows)]
921    ReadlineError::SystemError(_) => "Error",
922    _ => "Error",
923  }
924}
925
926fn get_signal_error(error: &SignalError) -> &'static str {
927  match error {
928    SignalError::InvalidSignalStr(_) => "TypeError",
929    SignalError::InvalidSignalInt(_) => "TypeError",
930    SignalError::SignalNotAllowed(_) => "TypeError",
931    SignalError::Io(e) => get_io_error_class(e),
932  }
933}
934
935fn get_fs_events_error(error: &FsEventsError) -> &'static str {
936  match error {
937    FsEventsError::Resource(e) => get_error_class_name(e).unwrap_or("Error"),
938    FsEventsError::Permission(e) => get_permission_check_error_class(e),
939    FsEventsError::Notify(e) => get_notify_error_class(e),
940    FsEventsError::Canceled(e) => {
941      let io_err: io::Error = e.to_owned().into();
942      get_io_error_class(&io_err)
943    }
944  }
945}
946
947fn get_http_start_error(error: &HttpStartError) -> &'static str {
948  match error {
949    HttpStartError::TcpStreamInUse => "Busy",
950    HttpStartError::TlsStreamInUse => "Busy",
951    HttpStartError::UnixSocketInUse => "Busy",
952    HttpStartError::ReuniteTcp(_) => "Error",
953    #[cfg(unix)]
954    HttpStartError::ReuniteUnix(_) => "Error",
955    HttpStartError::Io(e) => get_io_error_class(e),
956    HttpStartError::Other(e) => get_error_class_name(e).unwrap_or("Error"),
957  }
958}
959
960fn get_process_error(error: &ProcessError) -> &'static str {
961  match error {
962    ProcessError::SpawnFailed { error, .. } => get_process_error(error),
963    ProcessError::FailedResolvingCwd(e) | ProcessError::Io(e) => {
964      get_io_error_class(e)
965    }
966    ProcessError::Permission(e) => get_permission_check_error_class(e),
967    ProcessError::Resource(e) => get_error_class_name(e).unwrap_or("Error"),
968    ProcessError::BorrowMut(_) => "Error",
969    ProcessError::Which(_) => "Error",
970    ProcessError::ChildProcessAlreadyTerminated => "TypeError",
971    ProcessError::Signal(e) => get_signal_error(e),
972    ProcessError::MissingCmd => "Error",
973    ProcessError::InvalidPid => "TypeError",
974    #[cfg(unix)]
975    ProcessError::Nix(e) => get_nix_error_class(e),
976    ProcessError::RunPermission(e) => match e {
977      CheckRunPermissionError::Permission(e) => {
978        get_permission_check_error_class(e)
979      }
980      CheckRunPermissionError::Other(e) => {
981        get_error_class_name(e).unwrap_or("Error")
982      }
983    },
984  }
985}
986
987fn get_http_error(error: &HttpError) -> &'static str {
988  match error {
989    HttpError::Canceled(e) => {
990      let io_err: io::Error = e.to_owned().into();
991      get_io_error_class(&io_err)
992    }
993    HttpError::HyperV014(e) => get_hyper_v014_error_class(e),
994    HttpError::InvalidHeaderName(_) => "Error",
995    HttpError::InvalidHeaderValue(_) => "Error",
996    HttpError::Http(_) => "Error",
997    HttpError::ResponseHeadersAlreadySent => "Http",
998    HttpError::ConnectionClosedWhileSendingResponse => "Http",
999    HttpError::AlreadyInUse => "Http",
1000    HttpError::Io(e) => get_io_error_class(e),
1001    HttpError::NoResponseHeaders => "Http",
1002    HttpError::ResponseAlreadyCompleted => "Http",
1003    HttpError::UpgradeBodyUsed => "Http",
1004    HttpError::Resource(e) | HttpError::Other(e) => {
1005      get_error_class_name(e).unwrap_or("Error")
1006    }
1007  }
1008}
1009
1010fn get_http_next_error(error: &HttpNextError) -> &'static str {
1011  match error {
1012    HttpNextError::Io(e) => get_io_error_class(e),
1013    HttpNextError::WebSocketUpgrade(e) => get_websocket_upgrade_error(e),
1014    HttpNextError::Hyper(e) => get_hyper_error_class(e),
1015    HttpNextError::JoinError(_) => "Error",
1016    HttpNextError::Canceled(e) => {
1017      let io_err: io::Error = e.to_owned().into();
1018      get_io_error_class(&io_err)
1019    }
1020    HttpNextError::UpgradeUnavailable(_) => "Error",
1021    HttpNextError::HttpPropertyExtractor(e) | HttpNextError::Resource(e) => {
1022      get_error_class_name(e).unwrap_or("Error")
1023    }
1024  }
1025}
1026
1027fn get_websocket_upgrade_error(error: &WebSocketUpgradeError) -> &'static str {
1028  match error {
1029    WebSocketUpgradeError::InvalidHeaders => "Http",
1030    WebSocketUpgradeError::HttpParse(_) => "Error",
1031    WebSocketUpgradeError::Http(_) => "Error",
1032    WebSocketUpgradeError::Utf8(_) => "Error",
1033    WebSocketUpgradeError::InvalidHeaderName(_) => "Error",
1034    WebSocketUpgradeError::InvalidHeaderValue(_) => "Error",
1035    WebSocketUpgradeError::InvalidHttpStatusLine => "Http",
1036    WebSocketUpgradeError::UpgradeBufferAlreadyCompleted => "Http",
1037  }
1038}
1039
1040fn get_fs_error(e: &FsError) -> &'static str {
1041  match &e {
1042    FsError::Io(e) => get_io_error_class(e),
1043    FsError::FileBusy => "Busy",
1044    FsError::NotSupported => "NotSupported",
1045    FsError::NotCapable(_) => "NotCapable",
1046  }
1047}
1048
1049mod node {
1050  use super::get_error_class_name;
1051  use super::get_io_error_class;
1052  use super::get_permission_check_error_class;
1053  use super::get_serde_json_error_class;
1054  use super::get_url_parse_error_class;
1055  pub use deno_node::ops::blocklist::BlocklistError;
1056  pub use deno_node::ops::crypto::cipher::CipherContextError;
1057  pub use deno_node::ops::crypto::cipher::CipherError;
1058  pub use deno_node::ops::crypto::cipher::DecipherContextError;
1059  pub use deno_node::ops::crypto::cipher::DecipherError;
1060  pub use deno_node::ops::crypto::digest::HashError;
1061  pub use deno_node::ops::crypto::keys::AsymmetricPrivateKeyDerError;
1062  pub use deno_node::ops::crypto::keys::AsymmetricPrivateKeyError;
1063  pub use deno_node::ops::crypto::keys::AsymmetricPublicKeyDerError;
1064  pub use deno_node::ops::crypto::keys::AsymmetricPublicKeyError;
1065  pub use deno_node::ops::crypto::keys::AsymmetricPublicKeyJwkError;
1066  pub use deno_node::ops::crypto::keys::EcJwkError;
1067  pub use deno_node::ops::crypto::keys::EdRawError;
1068  pub use deno_node::ops::crypto::keys::ExportPrivateKeyPemError;
1069  pub use deno_node::ops::crypto::keys::ExportPublicKeyPemError;
1070  pub use deno_node::ops::crypto::keys::GenerateRsaPssError;
1071  pub use deno_node::ops::crypto::keys::RsaJwkError;
1072  pub use deno_node::ops::crypto::keys::RsaPssParamsParseError;
1073  pub use deno_node::ops::crypto::keys::X509PublicKeyError;
1074  pub use deno_node::ops::crypto::sign::KeyObjectHandlePrehashedSignAndVerifyError;
1075  pub use deno_node::ops::crypto::x509::X509Error;
1076  pub use deno_node::ops::crypto::DiffieHellmanError;
1077  pub use deno_node::ops::crypto::EcdhEncodePubKey;
1078  pub use deno_node::ops::crypto::HkdfError;
1079  pub use deno_node::ops::crypto::Pbkdf2Error;
1080  pub use deno_node::ops::crypto::PrivateEncryptDecryptError;
1081  pub use deno_node::ops::crypto::ScryptAsyncError;
1082  pub use deno_node::ops::crypto::SignEd25519Error;
1083  pub use deno_node::ops::crypto::VerifyEd25519Error;
1084  pub use deno_node::ops::fs::FsError;
1085  pub use deno_node::ops::http2::Http2Error;
1086  pub use deno_node::ops::idna::IdnaError;
1087  pub use deno_node::ops::ipc::IpcError;
1088  pub use deno_node::ops::ipc::IpcJsonStreamError;
1089  use deno_node::ops::os::priority::PriorityError;
1090  pub use deno_node::ops::os::OsError;
1091  pub use deno_node::ops::require::RequireError;
1092  use deno_node::ops::require::RequireErrorKind;
1093  pub use deno_node::ops::worker_threads::WorkerThreadsFilenameError;
1094  pub use deno_node::ops::zlib::brotli::BrotliError;
1095  pub use deno_node::ops::zlib::mode::ModeError;
1096  pub use deno_node::ops::zlib::ZlibError;
1097
1098  pub fn get_blocklist_error(error: &BlocklistError) -> &'static str {
1099    match error {
1100      BlocklistError::AddrParse(_) => "Error",
1101      BlocklistError::IpNetwork(_) => "Error",
1102      BlocklistError::InvalidAddress => "Error",
1103      BlocklistError::IpVersionMismatch => "Error",
1104    }
1105  }
1106
1107  pub fn get_fs_error(error: &FsError) -> &'static str {
1108    match error {
1109      FsError::Permission(e) => get_permission_check_error_class(e),
1110      FsError::Io(e) => get_io_error_class(e),
1111      #[cfg(windows)]
1112      FsError::PathHasNoRoot => "Error",
1113      #[cfg(not(any(unix, windows)))]
1114      FsError::UnsupportedPlatform => "Error",
1115      FsError::Fs(e) => super::get_fs_error(e),
1116    }
1117  }
1118
1119  pub fn get_idna_error(error: &IdnaError) -> &'static str {
1120    match error {
1121      IdnaError::InvalidInput => "RangeError",
1122      IdnaError::InputTooLong => "Error",
1123      IdnaError::IllegalInput => "RangeError",
1124    }
1125  }
1126
1127  pub fn get_ipc_json_stream_error(error: &IpcJsonStreamError) -> &'static str {
1128    match error {
1129      IpcJsonStreamError::Io(e) => get_io_error_class(e),
1130      IpcJsonStreamError::SimdJson(_) => "Error",
1131    }
1132  }
1133
1134  pub fn get_ipc_error(error: &IpcError) -> &'static str {
1135    match error {
1136      IpcError::Resource(e) => get_error_class_name(e).unwrap_or("Error"),
1137      IpcError::IpcJsonStream(e) => get_ipc_json_stream_error(e),
1138      IpcError::Canceled(e) => {
1139        let io_err: std::io::Error = e.to_owned().into();
1140        get_io_error_class(&io_err)
1141      }
1142      IpcError::SerdeJson(e) => get_serde_json_error_class(e),
1143    }
1144  }
1145
1146  pub fn get_worker_threads_filename_error(
1147    error: &WorkerThreadsFilenameError,
1148  ) -> &'static str {
1149    match error {
1150      WorkerThreadsFilenameError::Permission(e) => {
1151        get_error_class_name(e).unwrap_or("Error")
1152      }
1153      WorkerThreadsFilenameError::UrlParse(e) => get_url_parse_error_class(e),
1154      WorkerThreadsFilenameError::InvalidRelativeUrl => "Error",
1155      WorkerThreadsFilenameError::UrlFromPathString => "Error",
1156      WorkerThreadsFilenameError::UrlToPathString => "Error",
1157      WorkerThreadsFilenameError::UrlToPath => "Error",
1158      WorkerThreadsFilenameError::FileNotFound(_) => "Error",
1159      WorkerThreadsFilenameError::Fs(e) => super::get_fs_error(e),
1160    }
1161  }
1162
1163  pub fn get_require_error(error: &RequireError) -> &'static str {
1164    use RequireErrorKind::*;
1165    match error.as_kind() {
1166      UrlParse(e) => get_url_parse_error_class(e),
1167      Permission(e) => get_error_class_name(e).unwrap_or("Error"),
1168      PackageExportsResolve(_)
1169      | PackageJsonLoad(_)
1170      | ClosestPkgJson(_)
1171      | FilePathConversion(_)
1172      | UrlConversion(_)
1173      | ReadModule(_)
1174      | PackageImportsResolve(_) => "Error",
1175      Fs(e) | UnableToGetCwd(e) => super::get_fs_error(e),
1176    }
1177  }
1178
1179  pub fn get_http2_error(error: &Http2Error) -> &'static str {
1180    match error {
1181      Http2Error::Resource(e) => get_error_class_name(e).unwrap_or("Error"),
1182      Http2Error::UrlParse(e) => get_url_parse_error_class(e),
1183      Http2Error::H2(_) => "Error",
1184    }
1185  }
1186
1187  pub fn get_os_error(error: &OsError) -> &'static str {
1188    match error {
1189      OsError::Priority(e) => match e {
1190        PriorityError::Io(e) => get_io_error_class(e),
1191        #[cfg(windows)]
1192        PriorityError::InvalidPriority => "TypeError",
1193      },
1194      OsError::Permission(e) => get_permission_check_error_class(e),
1195      OsError::FailedToGetCpuInfo => "TypeError",
1196      OsError::FailedToGetUserInfo(e) => get_io_error_class(e),
1197    }
1198  }
1199
1200  pub fn get_brotli_error(error: &BrotliError) -> &'static str {
1201    match error {
1202      BrotliError::InvalidEncoderMode => "TypeError",
1203      BrotliError::CompressFailed => "TypeError",
1204      BrotliError::DecompressFailed => "TypeError",
1205      BrotliError::Join(_) => "Error",
1206      BrotliError::Resource(e) => get_error_class_name(e).unwrap_or("Error"),
1207      BrotliError::Io(e) => get_io_error_class(e),
1208    }
1209  }
1210
1211  pub fn get_mode_error(_: &ModeError) -> &'static str {
1212    "Error"
1213  }
1214
1215  pub fn get_zlib_error(e: &ZlibError) -> &'static str {
1216    match e {
1217      ZlibError::NotInitialized => "TypeError",
1218      ZlibError::Mode(e) => get_mode_error(e),
1219      ZlibError::Other(e) => get_error_class_name(e).unwrap_or("Error"),
1220    }
1221  }
1222
1223  pub fn get_crypto_cipher_context_error(
1224    e: &CipherContextError,
1225  ) -> &'static str {
1226    match e {
1227      CipherContextError::ContextInUse => "TypeError",
1228      CipherContextError::Cipher(e) => get_crypto_cipher_error(e),
1229      CipherContextError::Resource(e) => {
1230        get_error_class_name(e).unwrap_or("Error")
1231      }
1232    }
1233  }
1234
1235  pub fn get_crypto_cipher_error(e: &CipherError) -> &'static str {
1236    match e {
1237      CipherError::InvalidIvLength => "TypeError",
1238      CipherError::InvalidKeyLength => "RangeError",
1239      CipherError::InvalidInitializationVector => "TypeError",
1240      CipherError::CannotPadInputData => "TypeError",
1241      CipherError::UnknownCipher(_) => "TypeError",
1242    }
1243  }
1244
1245  pub fn get_crypto_decipher_context_error(
1246    e: &DecipherContextError,
1247  ) -> &'static str {
1248    match e {
1249      DecipherContextError::ContextInUse => "TypeError",
1250      DecipherContextError::Decipher(e) => get_crypto_decipher_error(e),
1251      DecipherContextError::Resource(e) => {
1252        get_error_class_name(e).unwrap_or("Error")
1253      }
1254    }
1255  }
1256
1257  pub fn get_crypto_decipher_error(e: &DecipherError) -> &'static str {
1258    match e {
1259      DecipherError::InvalidIvLength => "TypeError",
1260      DecipherError::InvalidKeyLength => "RangeError",
1261      DecipherError::InvalidInitializationVector => "TypeError",
1262      DecipherError::CannotUnpadInputData => "TypeError",
1263      DecipherError::DataAuthenticationFailed => "TypeError",
1264      DecipherError::SetAutoPaddingFalseAes128GcmUnsupported => "TypeError",
1265      DecipherError::SetAutoPaddingFalseAes256GcmUnsupported => "TypeError",
1266      DecipherError::UnknownCipher(_) => "TypeError",
1267    }
1268  }
1269
1270  pub fn get_x509_error(_: &X509Error) -> &'static str {
1271    "Error"
1272  }
1273
1274  pub fn get_crypto_key_object_handle_prehashed_sign_and_verify_error(
1275    e: &KeyObjectHandlePrehashedSignAndVerifyError,
1276  ) -> &'static str {
1277    match e {
1278      KeyObjectHandlePrehashedSignAndVerifyError::InvalidDsaSignatureEncoding => "TypeError",
1279      KeyObjectHandlePrehashedSignAndVerifyError::KeyIsNotPrivate => "TypeError",
1280      KeyObjectHandlePrehashedSignAndVerifyError::DigestNotAllowedForRsaSignature(_) => "TypeError",
1281      KeyObjectHandlePrehashedSignAndVerifyError::FailedToSignDigestWithRsa => "Error",
1282      KeyObjectHandlePrehashedSignAndVerifyError::DigestNotAllowedForRsaPssSignature(_) => "TypeError",
1283      KeyObjectHandlePrehashedSignAndVerifyError::FailedToSignDigestWithRsaPss => "Error",
1284      KeyObjectHandlePrehashedSignAndVerifyError::FailedToSignDigestWithDsa => "TypeError",
1285      KeyObjectHandlePrehashedSignAndVerifyError::RsaPssHashAlgorithmUnsupported => "TypeError",
1286      KeyObjectHandlePrehashedSignAndVerifyError::PrivateKeyDisallowsUsage { .. } => "TypeError",
1287      KeyObjectHandlePrehashedSignAndVerifyError::FailedToSignDigest => "TypeError",
1288      KeyObjectHandlePrehashedSignAndVerifyError::X25519KeyCannotBeUsedForSigning => "TypeError",
1289      KeyObjectHandlePrehashedSignAndVerifyError::Ed25519KeyCannotBeUsedForPrehashedSigning => "TypeError",
1290      KeyObjectHandlePrehashedSignAndVerifyError::DhKeyCannotBeUsedForSigning => "TypeError",
1291      KeyObjectHandlePrehashedSignAndVerifyError::KeyIsNotPublicOrPrivate => "TypeError",
1292      KeyObjectHandlePrehashedSignAndVerifyError::InvalidDsaSignature => "TypeError",
1293      KeyObjectHandlePrehashedSignAndVerifyError::X25519KeyCannotBeUsedForVerification => "TypeError",
1294      KeyObjectHandlePrehashedSignAndVerifyError::Ed25519KeyCannotBeUsedForPrehashedVerification => "TypeError",
1295      KeyObjectHandlePrehashedSignAndVerifyError::DhKeyCannotBeUsedForVerification => "TypeError",
1296    }
1297  }
1298
1299  pub fn get_crypto_hash_error(_: &HashError) -> &'static str {
1300    "Error"
1301  }
1302
1303  pub fn get_asymmetric_public_key_jwk_error(
1304    e: &AsymmetricPublicKeyJwkError,
1305  ) -> &'static str {
1306    match e {
1307      AsymmetricPublicKeyJwkError::UnsupportedJwkEcCurveP224 => "TypeError",
1308      AsymmetricPublicKeyJwkError::JwkExportNotImplementedForKeyType => {
1309        "TypeError"
1310      }
1311      AsymmetricPublicKeyJwkError::KeyIsNotAsymmetricPublicKey => "TypeError",
1312    }
1313  }
1314
1315  pub fn get_generate_rsa_pss_error(_: &GenerateRsaPssError) -> &'static str {
1316    "TypeError"
1317  }
1318
1319  pub fn get_asymmetric_private_key_der_error(
1320    e: &AsymmetricPrivateKeyDerError,
1321  ) -> &'static str {
1322    match e {
1323      AsymmetricPrivateKeyDerError::KeyIsNotAsymmetricPrivateKey => "TypeError",
1324      AsymmetricPrivateKeyDerError::InvalidRsaPrivateKey => "TypeError",
1325      AsymmetricPrivateKeyDerError::ExportingNonRsaPrivateKeyAsPkcs1Unsupported => "TypeError",
1326      AsymmetricPrivateKeyDerError::InvalidEcPrivateKey => "TypeError",
1327      AsymmetricPrivateKeyDerError::ExportingNonEcPrivateKeyAsSec1Unsupported => "TypeError",
1328      AsymmetricPrivateKeyDerError::ExportingNonRsaPssPrivateKeyAsPkcs8Unsupported => "Error",
1329      AsymmetricPrivateKeyDerError::InvalidDsaPrivateKey => "TypeError",
1330      AsymmetricPrivateKeyDerError::InvalidX25519PrivateKey => "TypeError",
1331      AsymmetricPrivateKeyDerError::InvalidEd25519PrivateKey => "TypeError",
1332      AsymmetricPrivateKeyDerError::InvalidDhPrivateKey => "TypeError",
1333      AsymmetricPrivateKeyDerError::UnsupportedKeyType(_) => "TypeError",
1334    }
1335  }
1336
1337  pub fn get_asymmetric_public_key_der_error(
1338    _: &AsymmetricPublicKeyDerError,
1339  ) -> &'static str {
1340    "TypeError"
1341  }
1342
1343  pub fn get_export_public_key_pem_error(
1344    e: &ExportPublicKeyPemError,
1345  ) -> &'static str {
1346    match e {
1347      ExportPublicKeyPemError::AsymmetricPublicKeyDer(e) => {
1348        get_asymmetric_public_key_der_error(e)
1349      }
1350      ExportPublicKeyPemError::VeryLargeData => "TypeError",
1351      ExportPublicKeyPemError::Der(_) => "Error",
1352    }
1353  }
1354
1355  pub fn get_export_private_key_pem_error(
1356    e: &ExportPrivateKeyPemError,
1357  ) -> &'static str {
1358    match e {
1359      ExportPrivateKeyPemError::AsymmetricPublicKeyDer(e) => {
1360        get_asymmetric_private_key_der_error(e)
1361      }
1362      ExportPrivateKeyPemError::VeryLargeData => "TypeError",
1363      ExportPrivateKeyPemError::Der(_) => "Error",
1364    }
1365  }
1366
1367  pub fn get_x509_public_key_error(e: &X509PublicKeyError) -> &'static str {
1368    match e {
1369      X509PublicKeyError::X509(_) => "Error",
1370      X509PublicKeyError::Rsa(_) => "Error",
1371      X509PublicKeyError::Asn1(_) => "Error",
1372      X509PublicKeyError::Ec(_) => "Error",
1373      X509PublicKeyError::UnsupportedEcNamedCurve => "TypeError",
1374      X509PublicKeyError::MissingEcParameters => "TypeError",
1375      X509PublicKeyError::MalformedDssPublicKey => "TypeError",
1376      X509PublicKeyError::UnsupportedX509KeyType => "TypeError",
1377    }
1378  }
1379
1380  pub fn get_rsa_jwk_error(e: &RsaJwkError) -> &'static str {
1381    match e {
1382      RsaJwkError::Base64(_) => "Error",
1383      RsaJwkError::Rsa(_) => "Error",
1384      RsaJwkError::MissingRsaPrivateComponent => "TypeError",
1385    }
1386  }
1387
1388  pub fn get_ec_jwk_error(e: &EcJwkError) -> &'static str {
1389    match e {
1390      EcJwkError::Ec(_) => "Error",
1391      EcJwkError::UnsupportedCurve(_) => "TypeError",
1392    }
1393  }
1394
1395  pub fn get_ed_raw_error(e: &EdRawError) -> &'static str {
1396    match e {
1397      EdRawError::Ed25519Signature(_) => "Error",
1398      EdRawError::InvalidEd25519Key => "TypeError",
1399      EdRawError::UnsupportedCurve => "TypeError",
1400    }
1401  }
1402
1403  pub fn get_pbkdf2_error(e: &Pbkdf2Error) -> &'static str {
1404    match e {
1405      Pbkdf2Error::UnsupportedDigest(_) => "TypeError",
1406      Pbkdf2Error::Join(_) => "Error",
1407    }
1408  }
1409
1410  pub fn get_scrypt_async_error(e: &ScryptAsyncError) -> &'static str {
1411    match e {
1412      ScryptAsyncError::Join(_) => "Error",
1413      ScryptAsyncError::Other(e) => get_error_class_name(e).unwrap_or("Error"),
1414    }
1415  }
1416
1417  pub fn get_hkdf_error_error(e: &HkdfError) -> &'static str {
1418    match e {
1419      HkdfError::ExpectedSecretKey => "TypeError",
1420      HkdfError::HkdfExpandFailed => "TypeError",
1421      HkdfError::UnsupportedDigest(_) => "TypeError",
1422      HkdfError::Join(_) => "Error",
1423    }
1424  }
1425
1426  pub fn get_rsa_pss_params_parse_error(
1427    _: &RsaPssParamsParseError,
1428  ) -> &'static str {
1429    "TypeError"
1430  }
1431
1432  pub fn get_asymmetric_private_key_error(
1433    e: &AsymmetricPrivateKeyError,
1434  ) -> &'static str {
1435    match e {
1436      AsymmetricPrivateKeyError::InvalidPemPrivateKeyInvalidUtf8(_) => "TypeError",
1437      AsymmetricPrivateKeyError::InvalidEncryptedPemPrivateKey => "TypeError",
1438      AsymmetricPrivateKeyError::InvalidPemPrivateKey => "TypeError",
1439      AsymmetricPrivateKeyError::EncryptedPrivateKeyRequiresPassphraseToDecrypt => "TypeError",
1440      AsymmetricPrivateKeyError::InvalidPkcs1PrivateKey => "TypeError",
1441      AsymmetricPrivateKeyError::InvalidSec1PrivateKey => "TypeError",
1442      AsymmetricPrivateKeyError::UnsupportedPemLabel(_) => "TypeError",
1443      AsymmetricPrivateKeyError::RsaPssParamsParse(e) => get_rsa_pss_params_parse_error(e),
1444      AsymmetricPrivateKeyError::InvalidEncryptedPkcs8PrivateKey => "TypeError",
1445      AsymmetricPrivateKeyError::InvalidPkcs8PrivateKey => "TypeError",
1446      AsymmetricPrivateKeyError::Pkcs1PrivateKeyDoesNotSupportEncryptionWithPassphrase => "TypeError",
1447      AsymmetricPrivateKeyError::Sec1PrivateKeyDoesNotSupportEncryptionWithPassphrase => "TypeError",
1448      AsymmetricPrivateKeyError::UnsupportedEcNamedCurve => "TypeError",
1449      AsymmetricPrivateKeyError::InvalidPrivateKey => "TypeError",
1450      AsymmetricPrivateKeyError::InvalidDsaPrivateKey => "TypeError",
1451      AsymmetricPrivateKeyError::MalformedOrMissingNamedCurveInEcParameters => "TypeError",
1452      AsymmetricPrivateKeyError::UnsupportedKeyType(_) => "TypeError",
1453      AsymmetricPrivateKeyError::UnsupportedKeyFormat(_) => "TypeError",
1454      AsymmetricPrivateKeyError::InvalidX25519PrivateKey => "TypeError",
1455      AsymmetricPrivateKeyError::X25519PrivateKeyIsWrongLength => "TypeError",
1456      AsymmetricPrivateKeyError::InvalidEd25519PrivateKey => "TypeError",
1457      AsymmetricPrivateKeyError::MissingDhParameters => "TypeError",
1458      AsymmetricPrivateKeyError::UnsupportedPrivateKeyOid => "TypeError",
1459    }
1460  }
1461
1462  pub fn get_asymmetric_public_key_error(
1463    e: &AsymmetricPublicKeyError,
1464  ) -> &'static str {
1465    match e {
1466      AsymmetricPublicKeyError::InvalidPemPrivateKeyInvalidUtf8(_) => {
1467        "TypeError"
1468      }
1469      AsymmetricPublicKeyError::InvalidPemPublicKey => "TypeError",
1470      AsymmetricPublicKeyError::InvalidPkcs1PublicKey => "TypeError",
1471      AsymmetricPublicKeyError::AsymmetricPrivateKey(e) => {
1472        get_asymmetric_private_key_error(e)
1473      }
1474      AsymmetricPublicKeyError::InvalidX509Certificate => "TypeError",
1475      AsymmetricPublicKeyError::X509(_) => "Error",
1476      AsymmetricPublicKeyError::X509PublicKey(e) => {
1477        get_x509_public_key_error(e)
1478      }
1479      AsymmetricPublicKeyError::UnsupportedPemLabel(_) => "TypeError",
1480      AsymmetricPublicKeyError::InvalidSpkiPublicKey => "TypeError",
1481      AsymmetricPublicKeyError::UnsupportedKeyType(_) => "TypeError",
1482      AsymmetricPublicKeyError::UnsupportedKeyFormat(_) => "TypeError",
1483      AsymmetricPublicKeyError::Spki(_) => "Error",
1484      AsymmetricPublicKeyError::Pkcs1(_) => "Error",
1485      AsymmetricPublicKeyError::RsaPssParamsParse(_) => "TypeError",
1486      AsymmetricPublicKeyError::MalformedDssPublicKey => "TypeError",
1487      AsymmetricPublicKeyError::MalformedOrMissingNamedCurveInEcParameters => {
1488        "TypeError"
1489      }
1490      AsymmetricPublicKeyError::MalformedOrMissingPublicKeyInEcSpki => {
1491        "TypeError"
1492      }
1493      AsymmetricPublicKeyError::Ec(_) => "Error",
1494      AsymmetricPublicKeyError::UnsupportedEcNamedCurve => "TypeError",
1495      AsymmetricPublicKeyError::MalformedOrMissingPublicKeyInX25519Spki => {
1496        "TypeError"
1497      }
1498      AsymmetricPublicKeyError::X25519PublicKeyIsTooShort => "TypeError",
1499      AsymmetricPublicKeyError::InvalidEd25519PublicKey => "TypeError",
1500      AsymmetricPublicKeyError::MissingDhParameters => "TypeError",
1501      AsymmetricPublicKeyError::MalformedDhParameters => "TypeError",
1502      AsymmetricPublicKeyError::MalformedOrMissingPublicKeyInDhSpki => {
1503        "TypeError"
1504      }
1505      AsymmetricPublicKeyError::UnsupportedPrivateKeyOid => "TypeError",
1506    }
1507  }
1508
1509  pub fn get_private_encrypt_decrypt_error(
1510    e: &PrivateEncryptDecryptError,
1511  ) -> &'static str {
1512    match e {
1513      PrivateEncryptDecryptError::Pkcs8(_) => "Error",
1514      PrivateEncryptDecryptError::Spki(_) => "Error",
1515      PrivateEncryptDecryptError::Utf8(_) => "Error",
1516      PrivateEncryptDecryptError::Rsa(_) => "Error",
1517      PrivateEncryptDecryptError::UnknownPadding => "TypeError",
1518    }
1519  }
1520
1521  pub fn get_ecdh_encode_pub_key_error(e: &EcdhEncodePubKey) -> &'static str {
1522    match e {
1523      EcdhEncodePubKey::InvalidPublicKey => "TypeError",
1524      EcdhEncodePubKey::UnsupportedCurve => "TypeError",
1525      EcdhEncodePubKey::Sec1(_) => "Error",
1526    }
1527  }
1528
1529  pub fn get_diffie_hellman_error(_: &DiffieHellmanError) -> &'static str {
1530    "TypeError"
1531  }
1532
1533  pub fn get_sign_ed25519_error(_: &SignEd25519Error) -> &'static str {
1534    "TypeError"
1535  }
1536
1537  pub fn get_verify_ed25519_error(_: &VerifyEd25519Error) -> &'static str {
1538    "TypeError"
1539  }
1540}
1541
1542fn get_os_error(error: &OsError) -> &'static str {
1543  match error {
1544    OsError::Permission(e) => get_permission_check_error_class(e),
1545    OsError::InvalidUtf8(_) => "InvalidData",
1546    OsError::EnvEmptyKey => "TypeError",
1547    OsError::EnvInvalidKey(_) => "TypeError",
1548    OsError::EnvInvalidValue(_) => "TypeError",
1549    OsError::Io(e) => get_io_error_class(e),
1550    OsError::Var(e) => get_env_var_error_class(e),
1551  }
1552}
1553
1554fn get_sync_fetch_error(error: &SyncFetchError) -> &'static str {
1555  match error {
1556    SyncFetchError::BlobUrlsNotSupportedInContext => "TypeError",
1557    SyncFetchError::Io(e) => get_io_error_class(e),
1558    SyncFetchError::InvalidScriptUrl => "TypeError",
1559    SyncFetchError::InvalidStatusCode(_) => "TypeError",
1560    SyncFetchError::ClassicScriptSchemeUnsupportedInWorkers(_) => "TypeError",
1561    SyncFetchError::InvalidUri(_) => "Error",
1562    SyncFetchError::InvalidMimeType(_) => "DOMExceptionNetworkError",
1563    SyncFetchError::MissingMimeType => "DOMExceptionNetworkError",
1564    SyncFetchError::Fetch(e) => get_fetch_error(e),
1565    SyncFetchError::Join(_) => "Error",
1566    SyncFetchError::Other(e) => get_error_class_name(e).unwrap_or("Error"),
1567  }
1568}
1569
1570pub fn get_error_class_name(e: &AnyError) -> Option<&'static str> {
1571  deno_core::error::get_custom_error_class(e)
1572    .or_else(|| {
1573      e.downcast_ref::<ChildPermissionError>()
1574        .map(get_child_permission_error)
1575    })
1576    .or_else(|| {
1577      e.downcast_ref::<PermissionCheckError>()
1578        .map(get_permission_check_error_class)
1579    })
1580    .or_else(|| {
1581      e.downcast_ref::<PermissionError>()
1582        .map(get_permission_error_class)
1583    })
1584    .or_else(|| e.downcast_ref::<FsError>().map(get_fs_error))
1585    .or_else(|| {
1586      e.downcast_ref::<node::BlocklistError>()
1587        .map(node::get_blocklist_error)
1588    })
1589    .or_else(|| e.downcast_ref::<node::FsError>().map(node::get_fs_error))
1590    .or_else(|| {
1591      e.downcast_ref::<node::IdnaError>()
1592        .map(node::get_idna_error)
1593    })
1594    .or_else(|| {
1595      e.downcast_ref::<node::IpcJsonStreamError>()
1596        .map(node::get_ipc_json_stream_error)
1597    })
1598    .or_else(|| e.downcast_ref::<node::IpcError>().map(node::get_ipc_error))
1599    .or_else(|| {
1600      e.downcast_ref::<node::WorkerThreadsFilenameError>()
1601        .map(node::get_worker_threads_filename_error)
1602    })
1603    .or_else(|| {
1604      e.downcast_ref::<node::RequireError>()
1605        .map(node::get_require_error)
1606    })
1607    .or_else(|| {
1608      e.downcast_ref::<node::Http2Error>()
1609        .map(node::get_http2_error)
1610    })
1611    .or_else(|| e.downcast_ref::<node::OsError>().map(node::get_os_error))
1612    .or_else(|| {
1613      e.downcast_ref::<node::BrotliError>()
1614        .map(node::get_brotli_error)
1615    })
1616    .or_else(|| {
1617      e.downcast_ref::<node::ModeError>()
1618        .map(node::get_mode_error)
1619    })
1620    .or_else(|| {
1621      e.downcast_ref::<node::ZlibError>()
1622        .map(node::get_zlib_error)
1623    })
1624    .or_else(|| {
1625      e.downcast_ref::<node::CipherError>()
1626        .map(node::get_crypto_cipher_error)
1627    })
1628    .or_else(|| {
1629      e.downcast_ref::<node::CipherContextError>()
1630        .map(node::get_crypto_cipher_context_error)
1631    })
1632    .or_else(|| {
1633      e.downcast_ref::<node::DecipherError>()
1634        .map(node::get_crypto_decipher_error)
1635    })
1636    .or_else(|| {
1637      e.downcast_ref::<node::DecipherContextError>()
1638        .map(node::get_crypto_decipher_context_error)
1639    })
1640    .or_else(|| {
1641      e.downcast_ref::<node::X509Error>()
1642        .map(node::get_x509_error)
1643    })
1644    .or_else(|| {
1645      e.downcast_ref::<node::KeyObjectHandlePrehashedSignAndVerifyError>()
1646        .map(node::get_crypto_key_object_handle_prehashed_sign_and_verify_error)
1647    })
1648    .or_else(|| {
1649      e.downcast_ref::<node::HashError>()
1650        .map(node::get_crypto_hash_error)
1651    })
1652    .or_else(|| {
1653      e.downcast_ref::<node::AsymmetricPublicKeyJwkError>()
1654        .map(node::get_asymmetric_public_key_jwk_error)
1655    })
1656    .or_else(|| {
1657      e.downcast_ref::<node::GenerateRsaPssError>()
1658        .map(node::get_generate_rsa_pss_error)
1659    })
1660    .or_else(|| {
1661      e.downcast_ref::<node::AsymmetricPrivateKeyDerError>()
1662        .map(node::get_asymmetric_private_key_der_error)
1663    })
1664    .or_else(|| {
1665      e.downcast_ref::<node::AsymmetricPublicKeyDerError>()
1666        .map(node::get_asymmetric_public_key_der_error)
1667    })
1668    .or_else(|| {
1669      e.downcast_ref::<node::ExportPublicKeyPemError>()
1670        .map(node::get_export_public_key_pem_error)
1671    })
1672    .or_else(|| {
1673      e.downcast_ref::<node::ExportPrivateKeyPemError>()
1674        .map(node::get_export_private_key_pem_error)
1675    })
1676    .or_else(|| {
1677      e.downcast_ref::<node::RsaJwkError>()
1678        .map(node::get_rsa_jwk_error)
1679    })
1680    .or_else(|| {
1681      e.downcast_ref::<node::EcJwkError>()
1682        .map(node::get_ec_jwk_error)
1683    })
1684    .or_else(|| {
1685      e.downcast_ref::<node::EdRawError>()
1686        .map(node::get_ed_raw_error)
1687    })
1688    .or_else(|| {
1689      e.downcast_ref::<node::Pbkdf2Error>()
1690        .map(node::get_pbkdf2_error)
1691    })
1692    .or_else(|| {
1693      e.downcast_ref::<node::ScryptAsyncError>()
1694        .map(node::get_scrypt_async_error)
1695    })
1696    .or_else(|| {
1697      e.downcast_ref::<node::HkdfError>()
1698        .map(node::get_hkdf_error_error)
1699    })
1700    .or_else(|| {
1701      e.downcast_ref::<node::RsaPssParamsParseError>()
1702        .map(node::get_rsa_pss_params_parse_error)
1703    })
1704    .or_else(|| {
1705      e.downcast_ref::<node::AsymmetricPrivateKeyError>()
1706        .map(node::get_asymmetric_private_key_error)
1707    })
1708    .or_else(|| {
1709      e.downcast_ref::<node::AsymmetricPublicKeyError>()
1710        .map(node::get_asymmetric_public_key_error)
1711    })
1712    .or_else(|| {
1713      e.downcast_ref::<node::PrivateEncryptDecryptError>()
1714        .map(node::get_private_encrypt_decrypt_error)
1715    })
1716    .or_else(|| {
1717      e.downcast_ref::<node::EcdhEncodePubKey>()
1718        .map(node::get_ecdh_encode_pub_key_error)
1719    })
1720    .or_else(|| {
1721      e.downcast_ref::<node::DiffieHellmanError>()
1722        .map(node::get_diffie_hellman_error)
1723    })
1724    .or_else(|| {
1725      e.downcast_ref::<node::SignEd25519Error>()
1726        .map(node::get_sign_ed25519_error)
1727    })
1728    .or_else(|| {
1729      e.downcast_ref::<node::VerifyEd25519Error>()
1730        .map(node::get_verify_ed25519_error)
1731    })
1732    .or_else(|| e.downcast_ref::<NApiError>().map(get_napi_error_class))
1733    .or_else(|| e.downcast_ref::<WebError>().map(get_web_error_class))
1734    .or_else(|| {
1735      e.downcast_ref::<CreateWorkerError>()
1736        .map(get_create_worker_error)
1737    })
1738    .or_else(|| e.downcast_ref::<TtyError>().map(get_tty_error))
1739    .or_else(|| e.downcast_ref::<ReadlineError>().map(get_readline_error))
1740    .or_else(|| e.downcast_ref::<SignalError>().map(get_signal_error))
1741    .or_else(|| e.downcast_ref::<FsEventsError>().map(get_fs_events_error))
1742    .or_else(|| e.downcast_ref::<HttpStartError>().map(get_http_start_error))
1743    .or_else(|| e.downcast_ref::<ProcessError>().map(get_process_error))
1744    .or_else(|| e.downcast_ref::<OsError>().map(get_os_error))
1745    .or_else(|| e.downcast_ref::<SyncFetchError>().map(get_sync_fetch_error))
1746    .or_else(|| {
1747      e.downcast_ref::<CompressionError>()
1748        .map(get_web_compression_error_class)
1749    })
1750    .or_else(|| {
1751      e.downcast_ref::<MessagePortError>()
1752        .map(get_web_message_port_error_class)
1753    })
1754    .or_else(|| {
1755      e.downcast_ref::<StreamResourceError>()
1756        .map(get_web_stream_resource_error_class)
1757    })
1758    .or_else(|| e.downcast_ref::<BlobError>().map(get_web_blob_error_class))
1759    .or_else(|| e.downcast_ref::<IRError>().map(|_| "TypeError"))
1760    .or_else(|| e.downcast_ref::<ReprError>().map(get_ffi_repr_error_class))
1761    .or_else(|| e.downcast_ref::<HttpError>().map(get_http_error))
1762    .or_else(|| e.downcast_ref::<HttpNextError>().map(get_http_next_error))
1763    .or_else(|| {
1764      e.downcast_ref::<WebSocketUpgradeError>()
1765        .map(get_websocket_upgrade_error)
1766    })
1767    .or_else(|| e.downcast_ref::<FsOpsError>().map(get_fs_ops_error))
1768    .or_else(|| {
1769      e.downcast_ref::<DlfcnError>()
1770        .map(get_ffi_dlfcn_error_class)
1771    })
1772    .or_else(|| {
1773      e.downcast_ref::<StaticError>()
1774        .map(get_ffi_static_error_class)
1775    })
1776    .or_else(|| {
1777      e.downcast_ref::<CallbackError>()
1778        .map(get_ffi_callback_error_class)
1779    })
1780    .or_else(|| e.downcast_ref::<CallError>().map(get_ffi_call_error_class))
1781    .or_else(|| e.downcast_ref::<TlsError>().map(get_tls_error_class))
1782    .or_else(|| e.downcast_ref::<CronError>().map(get_cron_error_class))
1783    .or_else(|| e.downcast_ref::<CanvasError>().map(get_canvas_error))
1784    .or_else(|| e.downcast_ref::<CacheError>().map(get_cache_error))
1785    .or_else(|| e.downcast_ref::<WebsocketError>().map(get_websocket_error))
1786    .or_else(|| {
1787      e.downcast_ref::<HandshakeError>()
1788        .map(get_websocket_handshake_error)
1789    })
1790    .or_else(|| e.downcast_ref::<KvError>().map(get_kv_error))
1791    .or_else(|| e.downcast_ref::<FetchError>().map(get_fetch_error))
1792    .or_else(|| {
1793      e.downcast_ref::<HttpClientCreateError>()
1794        .map(get_http_client_create_error)
1795    })
1796    .or_else(|| e.downcast_ref::<NetError>().map(get_net_error))
1797    .or_else(|| {
1798      e.downcast_ref::<deno_net::io::MapError>()
1799        .map(get_net_map_error)
1800    })
1801    .or_else(|| {
1802      e.downcast_ref::<BroadcastChannelError>()
1803        .map(get_broadcast_channel_error)
1804    })
1805    .or_else(|| {
1806      e.downcast_ref::<deno_webgpu::InitError>()
1807        .map(get_webgpu_error_class)
1808    })
1809    .or_else(|| {
1810      e.downcast_ref::<deno_webgpu::buffer::BufferError>()
1811        .map(get_webgpu_buffer_error_class)
1812    })
1813    .or_else(|| {
1814      e.downcast_ref::<deno_webgpu::bundle::BundleError>()
1815        .map(get_webgpu_bundle_error_class)
1816    })
1817    .or_else(|| {
1818      e.downcast_ref::<deno_webgpu::byow::ByowError>()
1819        .map(get_webgpu_byow_error_class)
1820    })
1821    .or_else(|| {
1822      e.downcast_ref::<deno_webgpu::render_pass::RenderPassError>()
1823        .map(get_webgpu_render_pass_error_class)
1824    })
1825    .or_else(|| {
1826      e.downcast_ref::<deno_webgpu::surface::SurfaceError>()
1827        .map(get_webgpu_surface_error_class)
1828    })
1829    .or_else(|| {
1830      e.downcast_ref::<DecryptError>()
1831        .map(get_crypto_decrypt_error_class)
1832    })
1833    .or_else(|| {
1834      e.downcast_ref::<EncryptError>()
1835        .map(get_crypto_encrypt_error_class)
1836    })
1837    .or_else(|| {
1838      e.downcast_ref::<deno_crypto::SharedError>()
1839        .map(get_crypto_shared_error_class)
1840    })
1841    .or_else(|| {
1842      e.downcast_ref::<deno_crypto::Ed25519Error>()
1843        .map(get_crypto_ed25519_error_class)
1844    })
1845    .or_else(|| {
1846      e.downcast_ref::<ExportKeyError>()
1847        .map(get_crypto_export_key_error_class)
1848    })
1849    .or_else(|| {
1850      e.downcast_ref::<GenerateKeyError>()
1851        .map(get_crypto_generate_key_error_class)
1852    })
1853    .or_else(|| {
1854      e.downcast_ref::<ImportKeyError>()
1855        .map(get_crypto_import_key_error_class)
1856    })
1857    .or_else(|| {
1858      e.downcast_ref::<deno_crypto::X448Error>()
1859        .map(get_crypto_x448_error_class)
1860    })
1861    .or_else(|| {
1862      e.downcast_ref::<deno_crypto::X25519Error>()
1863        .map(get_crypto_x25519_error_class)
1864    })
1865    .or_else(|| {
1866      e.downcast_ref::<deno_crypto::Error>()
1867        .map(get_crypto_error_class)
1868    })
1869    .or_else(|| {
1870      e.downcast_ref::<WebStorageError>()
1871        .map(get_webstorage_class_name)
1872    })
1873    .or_else(|| {
1874      e.downcast_ref::<deno_url::UrlPatternError>()
1875        .map(|_| "TypeError")
1876    })
1877    .or_else(|| {
1878      e.downcast_ref::<dlopen2::Error>()
1879        .map(get_dlopen_error_class)
1880    })
1881    .or_else(|| e.downcast_ref::<hyper::Error>().map(get_hyper_error_class))
1882    .or_else(|| {
1883      e.downcast_ref::<hyper_util::client::legacy::Error>()
1884        .map(get_hyper_util_error_class)
1885    })
1886    .or_else(|| {
1887      e.downcast_ref::<hyper_v014::Error>()
1888        .map(get_hyper_v014_error_class)
1889    })
1890    .or_else(|| {
1891      e.downcast_ref::<Arc<hyper_v014::Error>>()
1892        .map(|e| get_hyper_v014_error_class(e))
1893    })
1894    .or_else(|| {
1895      e.downcast_ref::<deno_core::Canceled>().map(|e| {
1896        let io_err: io::Error = e.to_owned().into();
1897        get_io_error_class(&io_err)
1898      })
1899    })
1900    .or_else(|| {
1901      e.downcast_ref::<env::VarError>()
1902        .map(get_env_var_error_class)
1903    })
1904    .or_else(|| e.downcast_ref::<io::Error>().map(get_io_error_class))
1905    .or_else(|| {
1906      e.downcast_ref::<ModuleResolutionError>()
1907        .map(get_module_resolution_error_class)
1908    })
1909    .or_else(|| {
1910      e.downcast_ref::<notify::Error>()
1911        .map(get_notify_error_class)
1912    })
1913    .or_else(|| e.downcast_ref::<regex::Error>().map(get_regex_error_class))
1914    .or_else(|| {
1915      e.downcast_ref::<serde_json::error::Error>()
1916        .map(get_serde_json_error_class)
1917    })
1918    .or_else(|| {
1919      e.downcast_ref::<url::ParseError>()
1920        .map(get_url_parse_error_class)
1921    })
1922    .or_else(|| {
1923      e.downcast_ref::<deno_kv::sqlite::SqliteBackendError>()
1924        .map(|_| "TypeError")
1925    })
1926    .or_else(|| {
1927      #[cfg(unix)]
1928      let maybe_get_nix_error_class =
1929        || e.downcast_ref::<nix::Error>().map(get_nix_error_class);
1930      #[cfg(not(unix))]
1931      let maybe_get_nix_error_class = || Option::<&'static str>::None;
1932      (maybe_get_nix_error_class)()
1933    })
1934}