diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2021-01-29 10:33:58 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-29 10:33:58 +0900 |
commit | fc162162a155faf088f2b1a3343597c66d59d98c (patch) | |
tree | be6831e9c52152753147fb4376815ab42325720f | |
parent | 6ecc86cf2ae4bb0aac6f3d0e954382a69176b387 (diff) |
fix(cli): fix panic in Deno.emit (#9302)
-rw-r--r-- | cli/ops/runtime_compiler.rs | 15 | ||||
-rw-r--r-- | cli/tests/compiler_api_test.ts | 13 |
2 files changed, 25 insertions, 3 deletions
diff --git a/cli/ops/runtime_compiler.rs b/cli/ops/runtime_compiler.rs index 481b29a11..60aa07bdd 100644 --- a/cli/ops/runtime_compiler.rs +++ b/cli/ops/runtime_compiler.rs @@ -10,6 +10,7 @@ use crate::specifier_handler::MemoryHandler; use crate::specifier_handler::SpecifierHandler; use deno_core::error::generic_error; +use deno_core::error::type_error; use deno_core::error::AnyError; use deno_core::error::Context; use deno_core::serde_json; @@ -55,6 +56,7 @@ async fn op_emit( ) -> Result<Value, AnyError> { deno_runtime::ops::check_unstable2(&state, "Deno.emit"); let args: EmitArgs = serde_json::from_value(args)?; + let root_specifier = args.root_specifier; let program_state = state.borrow().borrow::<Arc<ProgramState>>().clone(); let runtime_permissions = { let state = state.borrow(); @@ -92,9 +94,16 @@ async fn op_emit( None }; let mut builder = GraphBuilder::new(handler, maybe_import_map, None); - let root_specifier = - ModuleSpecifier::resolve_url_or_path(&args.root_specifier)?; - builder.add(&root_specifier, is_dynamic).await?; + let root_specifier = ModuleSpecifier::resolve_url_or_path(&root_specifier)?; + builder + .add(&root_specifier, is_dynamic) + .await + .map_err(|_| { + type_error(format!( + "Unable to handle the given specifier: {}", + &root_specifier + )) + })?; let bundle_type = match args.bundle { Some(RuntimeBundleType::Esm) => BundleType::Esm, _ => BundleType::None, diff --git a/cli/tests/compiler_api_test.ts b/cli/tests/compiler_api_test.ts index 17c02b0e5..99c7af961 100644 --- a/cli/tests/compiler_api_test.ts +++ b/cli/tests/compiler_api_test.ts @@ -292,3 +292,16 @@ Deno.test({ assert(diagnostics[0].messageText.includes("This import is never used")); }, }); + +Deno.test({ + name: "Deno.emit() - Unknown media type does not panic", + async fn() { + await assertThrowsAsync(async () => { + await Deno.emit("https://example.com/foo", { + sources: { + "https://example.com/foo": `let foo: string = "foo";`, + }, + }); + }); + }, +}); |