Uh oh!
There was an error while loading. Please reload this page.
util: inspect: do not crash on an Error stack pointing to itself - #58196
Conversation
802e28b to
8b819f9Compare
BridgeAR
left a comment
There was a problem hiding this comment.
LGTM. I am just surprised the regular circular detection does not pick this up. Do we know why?
The output does seem to be better in this case, so it's likely a good idea not to have the circular check trigger.
Should we maybe just add additional information that it's circular? That might be useful for users?
Open to ideas on how to show the circularity. I think it's a good idea. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@## main #58196 +/- ##
==========================================
+ Coverage 90.13% 90.14% +0.01%
==========================================
Files 630 637 +7 Lines 186780 188028 +1248 Branches 36653 36890 +237 ==========================================
+ Hits 168347 169504 +1157 - Misses 11207 11279 +72 - Partials 7226 7245 +19
🚀 New features to boost your workflow:
|
BridgeAR
commented
May 6, 2025
@SamVerschueren instead of only returning the ErrorPrototypeToString call result, we could add additional information that the stack is circular similar to the other circular outputs. |
SamVerschueren
commented
May 7, 2025
So I checked how it's done with objects where it looks like this The problem here though is that it's a method to get the stack string itself, so I don't see a way how to represent it in the same way more or less. So I just tried some things out in the case of the following code constfoo=newError('foo');foo.stack=foo;console.log(foo.stack);
Let me know what any one of you would like to see. Or something completely different, although might be a bit more work. But this deviates way too much from what it was I feel like. |
There was a problem hiding this comment.
I had a brief look into this and it does not fully fix the problem.
There are currently two spots where we miss to add adding the circular check (the other spot is for weird function names), since we have to special handle parts of the inspection before getting to the spot where we add the object to our circular check (it is intentionally at that spot to prevent doing it for e.g., empty objects, arrays, etc.).
One of them is here. Just comparing for a simple direct recursion does not prevent other cases, for example:
consterror=newError()consterror2=newError()error.stack=error2error2.stack=errorUh oh!
There was an error while loading. Please reload this page.
BridgeAR
commented
May 16, 2025
@SamVerschueren could you take another look? :) We could also land this as intermediate improvement and have another PR on top, I just thought it makes sense to combine the points that I looked at. |
SamVerschueren
commented
May 16, 2025
Yes I'll definitely look into this. I was out this week so I'll probably do it over the weekend. |
BridgeAR
commented
Jun 10, 2025
Ping @SamVerschueren |
SamVerschueren
commented
Jun 12, 2025
Ugh Sorry. I totally forgot about this. I'll do it tomorrow! |
nodejs-github-bot
commented
Jun 13, 2025
nodejs-github-bot
commented
Jun 13, 2025
nodejs-github-bot
commented
Jun 14, 2025
Uh oh!
There was an error while loading. Please reload this page.
nodejs-github-bot
commented
Jun 15, 2025
nodejs-github-bot
commented
Jun 16, 2025
Landed in ea5d37e |
PR-URL: #58196 Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
PR-URL: #58196 Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
PR-URL: #58196 Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
See #58195
This avoids a maximum call stack size exceeded crash when the error stack is pointing to the error itself
error.stack = error. This bug was introduced by #56573.