diff options
author | Casper Beyer <caspervonb@pm.me> | 2021-07-07 05:33:06 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-06 23:33:06 +0200 |
commit | 78ac19f51f48984ea16f97a0c574fa507544b8d5 (patch) | |
tree | 141f8665d88f1c8f2a80af3280e620217d9d82e2 | |
parent | 7edb1d713c036583e2ba3caf0df042835781a49c (diff) |
fix(repl): do not panic when Deno.inspect throws (#11292)
-rw-r--r-- | cli/tests/integration/repl_tests.rs | 21 | ||||
-rw-r--r-- | cli/tools/repl.rs | 8 |
2 files changed, 28 insertions, 1 deletions
diff --git a/cli/tests/integration/repl_tests.rs b/cli/tests/integration/repl_tests.rs index 00be42ac3..43ab32232 100644 --- a/cli/tests/integration/repl_tests.rs +++ b/cli/tests/integration/repl_tests.rs @@ -611,3 +611,24 @@ fn assign_underscore_error() { )); assert!(err.is_empty()); } + +#[test] +fn custom_inspect() { + let (out, err) = util::run_and_collect_output( + true, + "repl", + Some(vec![ + r#"const o = { + [Symbol.for("Deno.customInspect")]() { + throw new Error('Oops custom inspect error'); + }, + };"#, + "o", + ]), + Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]), + false, + ); + + assert!(out.contains("Oops custom inspect error")); + assert!(err.is_empty()); +} diff --git a/cli/tools/repl.rs b/cli/tools/repl.rs index 6c6d26240..662e1a8d7 100644 --- a/cli/tools/repl.rs +++ b/cli/tools/repl.rs @@ -564,7 +564,13 @@ impl ReplSession { "Runtime.callFunctionOn", Some(json!({ "executionContextId": self.context_id, - "functionDeclaration": "function (object) { return Deno[Deno.internal].inspectArgs(['%o', object], { colors: !Deno.noColor }); }", + "functionDeclaration": r#"function (object) { + try { + return Deno[Deno.internal].inspectArgs(["%o", object], { colors: !Deno.noColor }); + } catch (err) { + return Deno[Deno.internal].inspectArgs(["%o", err]); + } + }"#, "arguments": [ evaluate_result, ], |