From 2b8cee9a49e4e654df572f7ad1184f8bdd7a8865 Mon Sep 17 00:00:00 2001 From: "Kevin (Kun) \"Kassimo\" Qian" Date: Mon, 8 Oct 2018 08:36:09 -0700 Subject: [PATCH] Check thrown type, print String(...) if not instance of error (#939) Fixes #935 --- js/main.ts | 8 ++++++-- tests/error_007_any.ts | 1 + tests/error_007_any.ts.out | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 tests/error_007_any.ts create mode 100644 tests/error_007_any.ts.out diff --git a/js/main.ts b/js/main.ts index 2650371119..826d3e811b 100644 --- a/js/main.ts +++ b/js/main.ts @@ -25,9 +25,13 @@ function onGlobalError( source: string, lineno: number, colno: number, - error: Error + error: any // tslint:disable-line:no-any ) { - console.log(error.stack); + if (error instanceof Error) { + console.log(error.stack); + } else { + console.log(`Thrown: ${String(error)}`); + } os.exit(1); } diff --git a/tests/error_007_any.ts b/tests/error_007_any.ts new file mode 100644 index 0000000000..778886fcb9 --- /dev/null +++ b/tests/error_007_any.ts @@ -0,0 +1 @@ +throw {}; diff --git a/tests/error_007_any.ts.out b/tests/error_007_any.ts.out new file mode 100644 index 0000000000..13335a92c6 --- /dev/null +++ b/tests/error_007_any.ts.out @@ -0,0 +1 @@ +Thrown: [object Object]