2020-08-25 18:22:15 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
|
|
|
//! There are many types of errors in Deno:
|
2020-09-14 12:48:57 -04:00
|
|
|
//! - AnyError: a generic wrapper that can encapsulate any type of error.
|
2020-09-06 15:44:29 -04:00
|
|
|
//! - JsError: a container for the error message and stack trace for exceptions
|
2020-08-25 18:22:15 -04:00
|
|
|
//! thrown in JavaScript code. We use this to pretty-print stack traces.
|
|
|
|
//! - Diagnostic: these are errors that originate in TypeScript's compiler.
|
2020-09-14 12:48:57 -04:00
|
|
|
//! They're similar to JsError, in that they have line numbers. But
|
|
|
|
//! Diagnostics are compile-time type errors, whereas JsErrors are runtime
|
2020-08-25 18:22:15 -04:00
|
|
|
//! exceptions.
|
|
|
|
|
2020-09-14 08:27:44 -04:00
|
|
|
use crate::ast::DiagnosticBuffer;
|
2020-08-25 18:22:15 -04:00
|
|
|
use crate::import_map::ImportMapError;
|
2020-09-14 12:48:57 -04:00
|
|
|
use deno_core::error::AnyError;
|
2020-08-25 18:22:15 -04:00
|
|
|
|
|
|
|
fn get_import_map_error_class(_: &ImportMapError) -> &'static str {
|
|
|
|
"URIError"
|
|
|
|
}
|
|
|
|
|
2020-09-14 08:27:44 -04:00
|
|
|
fn get_diagnostic_class(_: &DiagnosticBuffer) -> &'static str {
|
2020-08-25 18:22:15 -04:00
|
|
|
"SyntaxError"
|
|
|
|
}
|
|
|
|
|
2020-09-14 12:48:57 -04:00
|
|
|
pub(crate) fn get_error_class_name(e: &AnyError) -> &'static str {
|
2020-12-13 13:45:53 -05:00
|
|
|
deno_runtime::errors::get_error_class_name(e)
|
2020-09-14 12:48:57 -04:00
|
|
|
.or_else(|| {
|
|
|
|
e.downcast_ref::<ImportMapError>()
|
|
|
|
.map(get_import_map_error_class)
|
|
|
|
})
|
|
|
|
.or_else(|| {
|
|
|
|
e.downcast_ref::<DiagnosticBuffer>()
|
|
|
|
.map(get_diagnostic_class)
|
|
|
|
})
|
|
|
|
.unwrap_or_else(|| {
|
|
|
|
panic!("Error '{}' contains boxed error of unknown type", e);
|
|
|
|
})
|
2020-08-25 18:22:15 -04:00
|
|
|
}
|