mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
fix(cli): give context when failed to load import map (#10478)
This commit is contained in:
parent
17118c41e4
commit
89b61b5d05
5 changed files with 46 additions and 2 deletions
|
@ -87,7 +87,13 @@ async fn op_emit(
|
||||||
let file = program_state
|
let file = program_state
|
||||||
.file_fetcher
|
.file_fetcher
|
||||||
.fetch(&import_map_specifier, &mut runtime_permissions)
|
.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)?
|
ImportMap::from_json(import_map_specifier.as_str(), &file.source)?
|
||||||
};
|
};
|
||||||
Some(import_map)
|
Some(import_map)
|
||||||
|
|
|
@ -101,7 +101,11 @@ impl ProgramState {
|
||||||
)?;
|
)?;
|
||||||
let file = file_fetcher
|
let file = file_fetcher
|
||||||
.fetch(&import_map_specifier, &mut Permissions::allow_all())
|
.fetch(&import_map_specifier, &mut Permissions::allow_all())
|
||||||
.await?;
|
.await
|
||||||
|
.context(format!(
|
||||||
|
"Unable to load '{}' import map",
|
||||||
|
import_map_specifier
|
||||||
|
))?;
|
||||||
let import_map =
|
let import_map =
|
||||||
ImportMap::from_json(import_map_specifier.as_str(), &file.source)?;
|
ImportMap::from_json(import_map_specifier.as_str(), &file.source)?;
|
||||||
Some(import_map)
|
Some(import_map)
|
||||||
|
|
|
@ -338,3 +338,22 @@ Deno.test({
|
||||||
assert(files["deno:///bundle.js"].endsWith("})();\n"));
|
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",
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
4
cli/tests/error_import_map_unable_to_load.out
Normal file
4
cli/tests/error_import_map_unable_to_load.out
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
error: Unable to load '[WILDCARD]' import map
|
||||||
|
|
||||||
|
Caused by:
|
||||||
|
[WILDCARD]
|
|
@ -3841,6 +3841,17 @@ console.log("finish");
|
||||||
http_server: true,
|
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]
|
#[test]
|
||||||
fn no_validate_asm() {
|
fn no_validate_asm() {
|
||||||
let output = util::deno_cmd()
|
let output = util::deno_cmd()
|
||||||
|
|
Loading…
Reference in a new issue