From 13493d9121da9f253cd601c18d2443e29e67dd29 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Sat, 11 Feb 2023 15:36:29 +0000 Subject: [PATCH] fix(cli/graph_util): don't append referrer info for root module errors (#17730) --- cli/graph_util.rs | 6 +++++- .../testdata/run/error_005_missing_dynamic_import.ts.out | 1 - .../testdata/run/error_015_dynamic_import_permissions.out | 1 - .../testdata/workers/permissions_dynamic_remote.ts.out | 1 - 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cli/graph_util.rs b/cli/graph_util.rs index e667714d6f..3fa849a713 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -57,6 +57,10 @@ pub fn graph_valid( walk_options: deno_graph::WalkOptions, ) -> Result<(), AnyError> { graph.walk(roots, walk_options).validate().map_err(|error| { + let is_root = match &error { + ModuleGraphError::ResolutionError(_) => false, + _ => roots.contains(error.specifier()), + }; let mut message = if let ModuleGraphError::ResolutionError(err) = &error { enhanced_resolution_error_message(err) } else { @@ -64,7 +68,7 @@ pub fn graph_valid( }; if let Some(range) = error.maybe_range() { - if !range.specifier.as_str().contains("/$deno$eval") { + if !is_root && !range.specifier.as_str().contains("/$deno$eval") { message.push_str(&format!("\n at {range}")); } } diff --git a/cli/tests/testdata/run/error_005_missing_dynamic_import.ts.out b/cli/tests/testdata/run/error_005_missing_dynamic_import.ts.out index 530c17f91f..55e4a85245 100644 --- a/cli/tests/testdata/run/error_005_missing_dynamic_import.ts.out +++ b/cli/tests/testdata/run/error_005_missing_dynamic_import.ts.out @@ -1,5 +1,4 @@ error: Uncaught (in promise) TypeError: Module not found "[WILDCARD]/bad-module.ts". - at file:///[WILDCARD]/error_005_missing_dynamic_import.ts:2:35 const _badModule = await import("./bad-module.ts"); ^ at async file://[WILDCARD]/error_005_missing_dynamic_import.ts:2:22 diff --git a/cli/tests/testdata/run/error_015_dynamic_import_permissions.out b/cli/tests/testdata/run/error_015_dynamic_import_permissions.out index 209e241a79..ef54f331b0 100644 --- a/cli/tests/testdata/run/error_015_dynamic_import_permissions.out +++ b/cli/tests/testdata/run/error_015_dynamic_import_permissions.out @@ -1,5 +1,4 @@ error: Uncaught (in promise) TypeError: Requires net access to "localhost:4545", run again with the --allow-net flag - at file:///[WILDCARD]/error_015_dynamic_import_permissions.js:2:16 await import("http://localhost:4545/subdir/mod4.js"); ^ at async file://[WILDCARD]/error_015_dynamic_import_permissions.js:2:3 diff --git a/cli/tests/testdata/workers/permissions_dynamic_remote.ts.out b/cli/tests/testdata/workers/permissions_dynamic_remote.ts.out index 2aeeb02e1d..cbddb61e04 100644 --- a/cli/tests/testdata/workers/permissions_dynamic_remote.ts.out +++ b/cli/tests/testdata/workers/permissions_dynamic_remote.ts.out @@ -1,5 +1,4 @@ error: Uncaught (in worker "") (in promise) TypeError: Requires net access to "example.com", run again with the --allow-net flag - at http://localhost:4545/workers/dynamic_remote.ts:2:14 await import("https://example.com/some/file.ts"); ^ at async http://localhost:4545/workers/dynamic_remote.ts:2:1