diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/fmt_errors.rs | 5 | ||||
-rw-r--r-- | cli/tests/integration/run_tests.rs | 11 | ||||
-rw-r--r-- | cli/tests/testdata/report_error.ts | 3 | ||||
-rw-r--r-- | cli/tests/testdata/report_error.ts.out | 5 | ||||
-rw-r--r-- | cli/tests/testdata/report_error_handled.ts | 19 | ||||
-rw-r--r-- | cli/tests/testdata/report_error_handled.ts.out | 13 |
6 files changed, 54 insertions, 2 deletions
diff --git a/cli/fmt_errors.rs b/cli/fmt_errors.rs index 953dfec8b..3016e0ff4 100644 --- a/cli/fmt_errors.rs +++ b/cli/fmt_errors.rs @@ -48,8 +48,9 @@ pub fn format_location(frame: &JsStackFrame) -> String { return cyan("native").to_string(); } let mut result = String::new(); - if let Some(file_name) = &frame.file_name { - result += &cyan(&format_file_name(file_name)).to_string(); + let file_name = frame.file_name.clone().unwrap_or_default(); + if !file_name.is_empty() { + result += &cyan(&format_file_name(&file_name)).to_string(); } else { if frame.is_eval { result += diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index b99ab2890..85363a27f 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -2753,3 +2753,14 @@ fn deno_no_prompt_environment_variable() { .unwrap(); assert!(output.status.success()); } + +itest!(report_error { + args: "run --quiet report_error.ts", + output: "report_error.ts.out", + exit_code: 1, +}); + +itest!(report_error_handled { + args: "run --quiet report_error_handled.ts", + output: "report_error_handled.ts.out", +}); diff --git a/cli/tests/testdata/report_error.ts b/cli/tests/testdata/report_error.ts new file mode 100644 index 000000000..a6d4af1fd --- /dev/null +++ b/cli/tests/testdata/report_error.ts @@ -0,0 +1,3 @@ +console.log(1); +reportError(new Error("foo")); +console.log(2); diff --git a/cli/tests/testdata/report_error.ts.out b/cli/tests/testdata/report_error.ts.out new file mode 100644 index 000000000..185db62a5 --- /dev/null +++ b/cli/tests/testdata/report_error.ts.out @@ -0,0 +1,5 @@ +1 +error: Uncaught Error: foo +reportError(new Error("foo")); + ^ + at [WILDCARD]/report_error.ts:2:13 diff --git a/cli/tests/testdata/report_error_handled.ts b/cli/tests/testdata/report_error_handled.ts new file mode 100644 index 000000000..de58f0b8e --- /dev/null +++ b/cli/tests/testdata/report_error_handled.ts @@ -0,0 +1,19 @@ +addEventListener("error", (event) => { + console.log({ + cancelable: event.cancelable, + message: event.message, + filename: event.filename, + lineno: event.lineno, + colno: event.colno, + error: event.error, + }); + event.preventDefault(); +}); + +onerror = (event) => { + console.log("onerror() called", event.error); +}; + +console.log(1); +reportError(new Error("foo")); +console.log(2); diff --git a/cli/tests/testdata/report_error_handled.ts.out b/cli/tests/testdata/report_error_handled.ts.out new file mode 100644 index 000000000..89fa30314 --- /dev/null +++ b/cli/tests/testdata/report_error_handled.ts.out @@ -0,0 +1,13 @@ +1 +{ + cancelable: true, + message: "Uncaught Error: foo", + filename: "[WILDCARD]/report_error_handled.ts", + lineno: 18, + colno: 13, + error: Error: foo + at [WILDCARD]/report_error_handled.ts:18:13 +} +onerror() called Error: foo + at [WILDCARD]/report_error_handled.ts:18:13 +2 |