diff --git a/cli/ops/runtime_compiler.rs b/cli/ops/runtime_compiler.rs index 481b29a110..60aa07bdd3 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 { 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::>().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 17c02b0e50..99c7af9616 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";`, + }, + }); + }); + }, +});