summaryrefslogtreecommitdiff
path: root/cli/errors.rs
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2021-10-11 08:26:22 +1100
committerGitHub <noreply@github.com>2021-10-11 08:26:22 +1100
commita7baf5f2bbb50dc0cb571de141b800b9155faca7 (patch)
tree4bebaabd1d3ed4595e8a388e0fae559bb5558974 /cli/errors.rs
parent5a8a989b7815023f33a1e3183a55cc8999af5d98 (diff)
refactor: integrate deno_graph into CLI (#12369)
Diffstat (limited to 'cli/errors.rs')
-rw-r--r--cli/errors.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/cli/errors.rs b/cli/errors.rs
index c26479b44..b09c3c01a 100644
--- a/cli/errors.rs
+++ b/cli/errors.rs
@@ -9,8 +9,12 @@
//! Diagnostics are compile-time type errors, whereas JsErrors are runtime
//! exceptions.
+use crate::emit::GraphError;
+
use deno_ast::Diagnostic;
use deno_core::error::AnyError;
+use deno_graph::ModuleGraphError;
+use deno_graph::ResolutionError;
use import_map::ImportMapError;
fn get_import_map_error_class(_: &ImportMapError) -> &'static str {
@@ -21,6 +25,34 @@ fn get_diagnostic_class(_: &Diagnostic) -> &'static str {
"SyntaxError"
}
+fn get_graph_error_class(err: &GraphError) -> &'static str {
+ get_module_graph_error_class(&err.0)
+}
+
+pub(crate) fn get_module_graph_error_class(
+ err: &ModuleGraphError,
+) -> &'static str {
+ match err {
+ ModuleGraphError::LoadingErr(_, err) => get_error_class_name(err.as_ref()),
+ ModuleGraphError::InvalidSource(_, _) => "SyntaxError",
+ ModuleGraphError::ParseErr(_, diagnostic) => {
+ get_diagnostic_class(diagnostic)
+ }
+ ModuleGraphError::ResolutionError(err) => get_resolution_error_class(err),
+ ModuleGraphError::UnsupportedMediaType(_, _) => "TypeError",
+ ModuleGraphError::Missing(_) => "NotFound",
+ }
+}
+
+fn get_resolution_error_class(err: &ResolutionError) -> &'static str {
+ match err {
+ ResolutionError::ResolverError(err, _, _) => {
+ get_error_class_name(err.as_ref())
+ }
+ _ => "TypeError",
+ }
+}
+
pub(crate) fn get_error_class_name(e: &AnyError) -> &'static str {
deno_runtime::errors::get_error_class_name(e)
.or_else(|| {
@@ -28,6 +60,15 @@ pub(crate) fn get_error_class_name(e: &AnyError) -> &'static str {
.map(get_import_map_error_class)
})
.or_else(|| e.downcast_ref::<Diagnostic>().map(get_diagnostic_class))
+ .or_else(|| e.downcast_ref::<GraphError>().map(get_graph_error_class))
+ .or_else(|| {
+ e.downcast_ref::<ModuleGraphError>()
+ .map(get_module_graph_error_class)
+ })
+ .or_else(|| {
+ e.downcast_ref::<ResolutionError>()
+ .map(get_resolution_error_class)
+ })
.unwrap_or_else(|| {
panic!(
"Error '{}' contains boxed error of unknown type:{}",