1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

fix: panic for runtime error in TS compiler (#6758)

This commit is contained in:
Bartek Iwańczuk 2020-07-15 14:23:17 +02:00 committed by GitHub
parent cde4dbb351
commit 73a9036089
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 3 deletions

View file

@ -0,0 +1 @@
Deno.compile("main.js", { "main.js": "console.log(foo);" });

View file

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

View file

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

View file

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