Skip to content

Commit

Permalink
Fix ErrorEvent handling to still play nice with my formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
rscarson committed Nov 4, 2024
1 parent e45656a commit d310ac1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/ext/web/init_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,12 @@ function formatException(error) {
/*
Need to process ErrorEvent here into an exception string
*/
const msg = error.message;
if (error.filename.length) {
return `${msg} at ${error.filename}:${error.lineno}:${error.colno}`;
} else {
return msg;
}
let filename = error.filename.length ? error.filename : undefined;
let lineno = error.filename.length ? error.lineno : undefined;
let error = new Error(error.message, filename, lineno);

// This is a bit of a hack, but we need to set the stack to the error event's error
throw error;
} else {
return `Uncaught ${inspectArgs([error], { colors: !getStderrNoColor() })}`;
}
Expand Down
31 changes: 31 additions & 0 deletions src/inner_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,37 @@ mod test_inner_runtime {
});
}

#[test]
fn test_async_load_errors() {
let module = Module::new(
"test.js",
"
throw new Error('msg');
",
);

let mut runtime = InnerRuntime::new(RuntimeOptions::default(), CancellationToken::new())
.expect("Could not load runtime");

let rt = &mut runtime;
let module_ = module.clone();
let result =
run_async_task(
|| async move { Ok(rt.load_modules(Some(&module_), vec![]).await.is_err()) },
);
assert!(result);

let mut runtime = InnerRuntime::new(RuntimeOptions::default(), CancellationToken::new())
.expect("Could not load runtime");

let rt = &mut runtime;
let result =
run_async_task(
|| async move { Ok(rt.load_modules(None, vec![&module]).await.is_err()) },
);
assert!(result);
}

#[test]
fn test_serialize_fn() {
let module = Module::new(
Expand Down

0 comments on commit d310ac1

Please sign in to comment.