diff options
author | Steven Guerrero <stephenguerrero43@gmail.com> | 2021-01-14 14:18:51 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-14 14:18:51 -0500 |
commit | 2d1208556ad09844407c484b1e23887e3ade97c7 (patch) | |
tree | e688ac2af56aa0dd12044c51cc9312c35de741e2 | |
parent | 979d71c883ee76c5e1246c5ad02f2791b745bef6 (diff) |
fix: don't swallow customInspect exceptions (#9095)
-rw-r--r-- | cli/tests/unit/console_test.ts | 19 | ||||
-rw-r--r-- | runtime/js/02_console.js | 18 |
2 files changed, 9 insertions, 28 deletions
diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts index 6f37c8050..64345be84 100644 --- a/cli/tests/unit/console_test.ts +++ b/cli/tests/unit/console_test.ts @@ -12,6 +12,7 @@ import { assert, assertEquals, assertStringIncludes, + assertThrows, unitTest, } from "./test_util.ts"; import { stripColor } from "../../../std/fmt/colors.ts"; @@ -834,19 +835,11 @@ unitTest(function consoleTestWithCustomInspectorError(): void { } } - assertEquals(stringify(new A()), "A {}"); - - class B { - constructor(public field: { a: string }) {} - [customInspect](): string { - return this.field.a; - } - } - - assertEquals(stringify(new B({ a: "a" })), "a"); - assertEquals( - stringify(B.prototype), - "B { [Symbol(Deno.customInspect)]: [Function: [Deno.customInspect]] }", + assertThrows( + () => stringify(new A()), + Error, + "BOOM", + "Custom inspect won't attempt to parse if user defined function throws", ); }); diff --git a/runtime/js/02_console.js b/runtime/js/02_console.js index c6c53977b..595bf5006 100644 --- a/runtime/js/02_console.js +++ b/runtime/js/02_console.js @@ -190,11 +190,7 @@ function inspectFunction(value, _ctx) { if (customInspect in value && typeof value[customInspect] === "function") { - try { - return String(value[customInspect]()); - } catch { - // pass - } + return String(value[customInspect]()); } // Might be Function/AsyncFunction/GeneratorFunction/AsyncGeneratorFunction let cstrName = Object.getPrototypeOf(value)?.constructor?.name; @@ -865,11 +861,7 @@ inspectOptions, ) { if (customInspect in value && typeof value[customInspect] === "function") { - try { - return String(value[customInspect]()); - } catch { - // pass - } + return String(value[customInspect]()); } // This non-unique symbol is used to support op_crates, ie. // in op_crates/web we don't want to depend on unique "Deno.customInspect" @@ -880,11 +872,7 @@ nonUniqueCustomInspect in value && typeof value[nonUniqueCustomInspect] === "function" ) { - try { - return String(value[nonUniqueCustomInspect]()); - } catch { - // pass - } + return String(value[nonUniqueCustomInspect]()); } if (value instanceof Error) { return String(value.stack); |