summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/compiler_js_error.ts1
-rw-r--r--cli/tests/compiler_js_error.ts.out7
-rw-r--r--cli/tests/integration_tests.rs6
-rw-r--r--cli/tsc.rs25
4 files changed, 36 insertions, 3 deletions
diff --git a/cli/tests/compiler_js_error.ts b/cli/tests/compiler_js_error.ts
new file mode 100644
index 000000000..0b981ae3a
--- /dev/null
+++ b/cli/tests/compiler_js_error.ts
@@ -0,0 +1 @@
+Deno.compile("main.js", { "main.js": "console.log(foo);" });
diff --git a/cli/tests/compiler_js_error.ts.out b/cli/tests/compiler_js_error.ts.out
new file mode 100644
index 000000000..8f1556731
--- /dev/null
+++ b/cli/tests/compiler_js_error.ts.out
@@ -0,0 +1,7 @@
+Check [WILDCARD]compiler_js_error.ts
+error: Uncaught Error: Error in TS compiler:
+Uncaught AssertionError: Unexpected skip of the emit.
+[WILDCARD]
+ at unwrapResponse ($deno$/ops/dispatch_json.ts:[WILDCARD])
+ at Object.sendAsync ($deno$/ops/dispatch_json.ts:[WILDCARD])
+ at async Object.compile ($deno$/compiler_api.ts:[WILDCARD])
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index 4df7a8268..f832358ff 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -2188,6 +2188,12 @@ itest!(deno_lint_glob {
exit_code: 1,
});
+itest!(compiler_js_error {
+ args: "run --unstable compiler_js_error.ts",
+ output: "compiler_js_error.ts.out",
+ exit_code: 1,
+});
+
#[test]
fn cafile_env_fetch() {
use url::Url;
diff --git a/cli/tsc.rs b/cli/tsc.rs
index 90531b9fb..dafee0259 100644
--- a/cli/tsc.rs
+++ b/cli/tsc.rs
@@ -7,6 +7,7 @@ use crate::doc::Location;
use crate::file_fetcher::SourceFile;
use crate::file_fetcher::SourceFileFetcher;
use crate::flags::Flags;
+use crate::fmt_errors::JSError;
use crate::global_state::GlobalState;
use crate::module_graph::ModuleGraph;
use crate::module_graph::ModuleGraphLoader;
@@ -1160,6 +1161,18 @@ async fn create_runtime_module_graph(
Ok((root_names, module_graph_loader.get_graph()))
}
+/// Because TS compiler can raise runtime error, we need to
+/// manually convert formatted JSError into and OpError.
+fn js_error_to_op_error(error: ErrBox) -> OpError {
+ match error.downcast::<JSError>() {
+ Ok(js_error) => {
+ let msg = format!("Error in TS compiler:\n{}", js_error);
+ OpError::other(msg)
+ }
+ Err(error) => error.into(),
+ }
+}
+
/// This function is used by `Deno.compile()` API.
pub async fn runtime_compile(
global_state: GlobalState,
@@ -1193,7 +1206,9 @@ pub async fn runtime_compile(
let compiler = global_state.ts_compiler.clone();
- let msg = execute_in_same_thread(global_state, permissions, req_msg).await?;
+ let msg = execute_in_same_thread(global_state, permissions, req_msg)
+ .await
+ .map_err(js_error_to_op_error)?;
let json_str = std::str::from_utf8(&msg).unwrap();
let response: RuntimeCompileResponse = serde_json::from_str(json_str)?;
@@ -1239,7 +1254,9 @@ pub async fn runtime_bundle(
.into_boxed_str()
.into_boxed_bytes();
- let msg = execute_in_same_thread(global_state, permissions, req_msg).await?;
+ let msg = execute_in_same_thread(global_state, permissions, req_msg)
+ .await
+ .map_err(js_error_to_op_error)?;
let json_str = std::str::from_utf8(&msg).unwrap();
let _response: RuntimeBundleResponse = serde_json::from_str(json_str)?;
// We're returning `Ok()` instead of `Err()` because it's not runtime
@@ -1264,7 +1281,9 @@ pub async fn runtime_transpile(
.into_boxed_str()
.into_boxed_bytes();
- let msg = execute_in_same_thread(global_state, permissions, req_msg).await?;
+ let msg = execute_in_same_thread(global_state, permissions, req_msg)
+ .await
+ .map_err(js_error_to_op_error)?;
let json_str = std::str::from_utf8(&msg).unwrap();
let v = serde_json::from_str::<serde_json::Value>(json_str)
.expect("Error decoding JSON string.");