summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorJason <m.jason.liu@outlook.com>2022-09-02 19:38:06 +0800
committerGitHub <noreply@github.com>2022-09-02 13:38:06 +0200
commit8178665bd1877a55a4e82b07d6ac4a749c8a9c1c (patch)
tree74ba2bf20abbe3ba44080b9177489ff117b097f7 /cli
parenta74b2ecf379ddb1ff03c61d4e876153d7b4c45d2 (diff)
fix(cli/repl): await Promise.any([])... (#15623)
Diffstat (limited to 'cli')
-rw-r--r--cli/tests/integration/repl_tests.rs14
-rw-r--r--cli/tests/unit/console_test.ts11
-rw-r--r--cli/tools/repl/session.rs20
3 files changed, 38 insertions, 7 deletions
diff --git a/cli/tests/integration/repl_tests.rs b/cli/tests/integration/repl_tests.rs
index 07b7575a0..cdeb36c9c 100644
--- a/cli/tests/integration/repl_tests.rs
+++ b/cli/tests/integration/repl_tests.rs
@@ -861,3 +861,17 @@ fn repl_report_error() {
assert_contains!(out, "1\n2\nundefined\n");
assert!(err.is_empty());
}
+
+#[test]
+fn pty_aggregate_error() {
+ let (out, err) = util::run_and_collect_output(
+ true,
+ "repl",
+ Some(vec!["await Promise.any([])"]),
+ Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]),
+ false,
+ );
+
+ assert_contains!(out, "AggregateError");
+ assert!(err.is_empty());
+}
diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts
index 1b364eda1..1faef6bd7 100644
--- a/cli/tests/unit/console_test.ts
+++ b/cli/tests/unit/console_test.ts
@@ -2027,3 +2027,14 @@ Deno.test(function inspectStringAbbreviation() {
'[ "This is a ..." ]',
);
});
+
+Deno.test(async function inspectAggregateError() {
+ try {
+ await Promise.any([]);
+ } catch (err) {
+ assertEquals(
+ Deno.inspect(err).trimEnd(),
+ "AggregateError: All promises were rejected",
+ );
+ }
+});
diff --git a/cli/tools/repl/session.rs b/cli/tools/repl/session.rs
index d5058ab72..f2cdfe568 100644
--- a/cli/tools/repl/session.rs
+++ b/cli/tools/repl/session.rs
@@ -165,8 +165,18 @@ impl ReplSession {
exception_details,
} = evaluate_response.value;
- if exception_details.is_some() {
+ Ok(if let Some(exception_details) = exception_details {
self.set_last_thrown_error(&result).await?;
+ let description = match exception_details.exception {
+ Some(exception) => exception
+ .description
+ .unwrap_or_else(|| "Unknown exception".to_string()),
+ None => "Unknown exception".to_string(),
+ };
+ EvaluationOutput::Error(format!(
+ "{} {}",
+ exception_details.text, description
+ ))
} else {
self
.language_server
@@ -174,12 +184,8 @@ impl ReplSession {
.await;
self.set_last_eval_result(&result).await?;
- }
-
- let value = self.get_eval_value(&result).await?;
- Ok(match exception_details {
- Some(_) => EvaluationOutput::Error(format!("Uncaught {}", value)),
- None => EvaluationOutput::Value(value),
+ let value = self.get_eval_value(&result).await?;
+ EvaluationOutput::Value(value)
})
}
Err(err) => {