1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

fix(cli): give context when failed to load import map (#10478)

This commit is contained in:
Satya Rohith 2021-05-04 17:57:20 +05:30 committed by GitHub
parent 17118c41e4
commit 89b61b5d05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 2 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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",
);
},
});

View file

@ -0,0 +1,4 @@
error: Unable to load '[WILDCARD]' import map
Caused by:
[WILDCARD]

View file

@ -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()