summaryrefslogtreecommitdiff
path: root/cli/rt/02_console.js
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2020-10-01 10:25:34 +0100
committerGitHub <noreply@github.com>2020-10-01 11:25:34 +0200
commitb689e60b602be547c701094ba76fe3a545cad70d (patch)
treec7ddde2efe7bbfeb22b377c52c1b381efaf70ac6 /cli/rt/02_console.js
parent290da280a8a8ab8f886462cd61484f5a6a4d57a4 (diff)
fix(cli/console): Catch and format getter errors (#7766)
Diffstat (limited to 'cli/rt/02_console.js')
-rw-r--r--cli/rt/02_console.js44
1 files changed, 24 insertions, 20 deletions
diff --git a/cli/rt/02_console.js b/cli/rt/02_console.js
index b5cab7617..913ea44f2 100644
--- a/cli/rt/02_console.js
+++ b/cli/rt/02_console.js
@@ -762,29 +762,33 @@
);
}
+ const red = maybeColor(colors.red, inspectOptions);
+
for (const key of stringKeys) {
- entries.push(
- `${maybeQuoteString(key)}: ${
- inspectValueWithQuotes(
- value[key],
- ctx,
- level + 1,
- inspectOptions,
- )
- }`,
- );
+ let propertyValue;
+ let error = null;
+ try {
+ propertyValue = value[key];
+ } catch (error_) {
+ error = error_;
+ }
+ const inspectedValue = error == null
+ ? inspectValueWithQuotes(propertyValue, ctx, level + 1, inspectOptions)
+ : red(`[Thrown ${error.name}: ${error.message}]`);
+ entries.push(`${maybeQuoteString(key)}: ${inspectedValue}`);
}
for (const key of symbolKeys) {
- entries.push(
- `[${maybeQuoteSymbol(key)}]: ${
- inspectValueWithQuotes(
- value[key],
- ctx,
- level + 1,
- inspectOptions,
- )
- }`,
- );
+ let propertyValue;
+ let error;
+ try {
+ propertyValue = value[key];
+ } catch (error_) {
+ error = error_;
+ }
+ const inspectedValue = error == null
+ ? inspectValueWithQuotes(propertyValue, ctx, level + 1, inspectOptions)
+ : red(`Thrown ${error.name}: ${error.message}`);
+ entries.push(`[${maybeQuoteSymbol(key)}]: ${inspectedValue}`);
}
// Making sure color codes are ignored when calculating the total length
const totalLength = entries.length + level +