1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

fix(repl): correctly print string exception (#19391)

Fixes a recent regression where `throw "hello"` in the repl prints
`Uncaught undefined` instead of `throw "hello"`
This commit is contained in:
sigmaSd 2023-06-06 22:06:30 +01:00 committed by GitHub
parent 40d77c5605
commit 455b0eb8bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View file

@ -814,6 +814,10 @@ fn repl_reject() {
console.expect(" at <anonymous>");
console.write_line("console.log(2);");
console.expect("2");
console.write_line(r#"throw "hello";"#);
console.expect(r#"Uncaught "hello""#);
console.write_line(r#"throw `hello ${"world"}`;"#);
console.expect(r#"Uncaught "hello world""#);
});
}

View file

@ -258,9 +258,15 @@ impl ReplSession {
Ok(if let Some(exception_details) = exception_details {
session.set_last_thrown_error(&result).await?;
let description = match exception_details.exception {
Some(exception) => exception
.description
.unwrap_or_else(|| "undefined".to_string()),
Some(exception) => {
if let Some(description) = exception.description {
description
} else if let Some(value) = exception.value {
value.to_string()
} else {
"undefined".to_string()
}
}
None => "Unknown exception".to_string(),
};
EvaluationOutput::Error(format!(