Skip to content

Commit d1b18c0

Browse files
committed
fixup! util: handle uncommon thrown errors
1 parent 796a225 commit d1b18c0

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

lib/internal/util/inspect.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,13 +2557,14 @@ function formatProperty(ctx, value, recurseTimes, key, type, desc,
25572557
}
25582558
ctx.indentationLvl -= 2;
25592559
} catch (err) {
2560-
let messageSuffix;
2560+
// Error message itself may be a getter
2561+
let errMessage;
25612562
try {
2562-
// Error message itself may be a getter
2563-
messageSuffix = ` (${err.message})`;
2563+
errMessage = err.message;
25642564
} catch {
2565-
messageSuffix = '';
2565+
errMessage = undefined;
25662566
}
2567+
const messageSuffix = typeof errMessage === 'string' ? ` (${errMessage})` : '';
25672568
const message = `<Inspection threw${messageSuffix}>`;
25682569
str = `${s(`[${label}:`, sp)} ${message}${s(']', sp)}`;
25692570
}

test/parallel/test-util-inspect.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,20 +2565,20 @@ assert.strictEqual(
25652565
/* eslint-disable-next-line no-throw-literal */
25662566
get foo() { throw true; }
25672567
}, { getters: true }),
2568-
'{ foo: [Getter: <Inspection threw (undefined)>] }'
2568+
'{ foo: [Getter: <Inspection threw>] }'
25692569
);
25702570
assert.strictEqual(
25712571
inspect({
25722572
/* eslint-disable-next-line no-throw-literal */
25732573
get foo() { throw {}; }
25742574
}, { getters: true }),
2575-
'{ foo: [Getter: <Inspection threw (undefined)>] }'
2575+
'{ foo: [Getter: <Inspection threw>] }'
25762576
);
25772577
assert.strictEqual(
25782578
inspect({
25792579
get foo() { throw Error; }
25802580
}, { getters: true }),
2581-
'{ foo: [Getter: <Inspection threw (undefined)>] }'
2581+
'{ foo: [Getter: <Inspection threw>] }'
25822582
);
25832583
}
25842584

0 commit comments

Comments
 (0)