-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util: inspect: do not crash on an Error stack that contains a Symbol #56573
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -770,23 +770,25 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324'); | |
// Note: Symbols are not supported by `Error#toString()` which is called by | ||
// accessing the `stack` property. | ||
[ | ||
[404, '404 [RangeError]: foo', '[404]'], | ||
// [404, '404 [RangeError]: foo', '[404]'], | ||
[0, '0 [RangeError]: foo', '[RangeError: foo]'], | ||
[0n, '0 [RangeError]: foo', '[RangeError: foo]'], | ||
[null, 'null: foo', '[RangeError: foo]'], | ||
[undefined, 'RangeError: foo', '[RangeError: foo]'], | ||
[false, 'false [RangeError]: foo', '[RangeError: foo]'], | ||
['', 'foo', '[RangeError: foo]'], | ||
[[1, 2, 3], '1,2,3 [RangeError]: foo', '[1,2,3]'], | ||
[[1, 2, 3], '1,2,3 [RangeError]: foo', '[[\n 1,\n 2,\n 3\n]]'], | ||
].forEach(([value, outputStart, stack]) => { | ||
let err = new RangeError('foo'); | ||
err.name = value; | ||
const result = util.inspect(err); | ||
assert( | ||
util.inspect(err).startsWith(outputStart), | ||
result.startsWith(outputStart), | ||
util.format( | ||
'The name set to %o did not result in the expected output "%s"', | ||
'The name set to %o did not result in the expected output "%s", got "%s"', | ||
value, | ||
outputStart | ||
outputStart, | ||
result.split('\n')[0] | ||
) | ||
); | ||
|
||
|
@@ -3448,3 +3450,13 @@ assert.strictEqual( | |
${error.stack.split('\n').slice(1).join('\n')}`, | ||
); | ||
} | ||
|
||
{ | ||
const error = new Error(); | ||
error.stack = [Symbol('foo')]; | ||
|
||
assert.strictEqual( | ||
inspect(error), | ||
'[[\n Symbol(foo)\n]]' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we change the
I think that would be beneficial. Otherwise it's going to be very tricky to understand what the output is about. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, it seems like assigning |
||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per discussion, this change breaks some output. is it ok to land this as-is?