-
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?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #56573 +/- ##
==========================================
- Coverage 89.21% 89.14% -0.07%
==========================================
Files 662 662
Lines 191934 191940 +6
Branches 36945 36889 -56
==========================================
- Hits 171227 171114 -113
- Misses 13543 13672 +129
+ Partials 7164 7154 -10
|
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.
We could try to still log something more helpful than just the array with the symbol in it. Something like:
Error
[Symbol(foo)]
We just have to detect it's deviating from regular errors.
0a8293c
to
8ed3e8b
Compare
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.
Landing this as is is an improvement over the current situation (since it does not error anymore), while I believe we should push for a tad more and show the error name and message as well.
|
||
assert.strictEqual( | ||
inspect(error), | ||
'[[\n Symbol(foo)\n]]' |
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.
Could we change the improveStack()
method to result in:
Error: message
[\n
Symbol(foo)\n
]
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, it seems like assigning .name
stringifies it immediately, so we can't alter rendering behavior based on that later. Thoughts?
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.
After giving it another thought, I think it is best to land this as is and improve the error output later.
Error output for these cases is broken one way or the other and this is an improvement, even without the other part (which is tricky, since stack traces can have an arbitrary shape).
if (error.stack) { | ||
if (typeof error.stack === 'string') { | ||
return error.stack; | ||
} | ||
return formatValue(ctx, error.stack); | ||
} |
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.
if (error.stack) { | |
if (typeof error.stack === 'string') { | |
return error.stack; | |
} | |
return formatValue(ctx, error.stack); | |
} | |
if (typeof error.stack === 'string') { | |
return error.stack; | |
} | |
if (error.stack != null) { | |
return formatValue(ctx, error.stack); | |
} |
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?
2e0f183
to
3523bf2
Compare
3523bf2
to
ce97b94
Compare
See #56570 - this avoids a crash when an Error's
stack
property contains a Symbol inside an array