summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/ops/runtime_compiler.rs8
-rw-r--r--cli/program_state.rs6
-rw-r--r--cli/tests/compiler_api_test.ts19
-rw-r--r--cli/tests/error_import_map_unable_to_load.out4
-rw-r--r--cli/tests/integration_tests.rs11
5 files changed, 46 insertions, 2 deletions
diff --git a/cli/ops/runtime_compiler.rs b/cli/ops/runtime_compiler.rs
index 4865c1045..8e3ca80b5 100644
--- a/cli/ops/runtime_compiler.rs
+++ b/cli/ops/runtime_compiler.rs
@@ -87,7 +87,13 @@ async fn op_emit(
let file = program_state
.file_fetcher
.fetch(&import_map_specifier, &mut runtime_permissions)
- .await?;
+ .await
+ .map_err(|e| {
+ generic_error(format!(
+ "Unable to load '{}' import map: {}",
+ import_map_specifier, e
+ ))
+ })?;
ImportMap::from_json(import_map_specifier.as_str(), &file.source)?
};
Some(import_map)
diff --git a/cli/program_state.rs b/cli/program_state.rs
index de6331b89..e8d2c163e 100644
--- a/cli/program_state.rs
+++ b/cli/program_state.rs
@@ -101,7 +101,11 @@ impl ProgramState {
)?;
let file = file_fetcher
.fetch(&import_map_specifier, &mut Permissions::allow_all())
- .await?;
+ .await
+ .context(format!(
+ "Unable to load '{}' import map",
+ import_map_specifier
+ ))?;
let import_map =
ImportMap::from_json(import_map_specifier.as_str(), &file.source)?;
Some(import_map)
diff --git a/cli/tests/compiler_api_test.ts b/cli/tests/compiler_api_test.ts
index 04a4675b8..c6e7de651 100644
--- a/cli/tests/compiler_api_test.ts
+++ b/cli/tests/compiler_api_test.ts
@@ -338,3 +338,22 @@ Deno.test({
assert(files["deno:///bundle.js"].endsWith("})();\n"));
},
});
+
+Deno.test({
+ name: `Deno.emit() - throws descriptive error when unable to load import map`,
+ async fn() {
+ await assertThrowsAsync(
+ async () => {
+ await Deno.emit("/a.ts", {
+ bundle: "classic",
+ sources: {
+ "/a.ts": `console.log("hello");`,
+ },
+ importMapPath: "file:///import_map_does_not_exist.json",
+ });
+ },
+ Error,
+ "Unable to load 'file:///import_map_does_not_exist.json' import map",
+ );
+ },
+});
diff --git a/cli/tests/error_import_map_unable_to_load.out b/cli/tests/error_import_map_unable_to_load.out
new file mode 100644
index 000000000..50760e438
--- /dev/null
+++ b/cli/tests/error_import_map_unable_to_load.out
@@ -0,0 +1,4 @@
+error: Unable to load '[WILDCARD]' import map
+
+Caused by:
+ [WILDCARD] \ No newline at end of file
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index 5cbe00302..f2d1c1770 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -3841,6 +3841,17 @@ console.log("finish");
http_server: true,
});
+ // This test ensures that a descriptive error is shown when we're unable to load
+ // the import map. Even though this tests only the `run` subcommand, we can be sure
+ // that the error message is similar for other subcommands as they all use
+ // `program_state.maybe_import_map` to access the import map underneath.
+ itest!(error_import_map_unable_to_load {
+ args:
+ "run --import-map=import_maps/does_not_exist.json import_maps/test.ts",
+ output: "error_import_map_unable_to_load.out",
+ exit_code: 1,
+ });
+
#[test]
fn no_validate_asm() {
let output = util::deno_cmd()