-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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: fix isInsideNodeModules inside error #20266
Conversation
When isInsideNodeModules gets called while already processing another stack trace, V8 will not call prepareStackTrace again. This used to cause Node.js to just crash — fix it by checking for expected return type of the stack (Array).
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.
LGTM
if (!/^\/|\\/.test(filename)) | ||
continue; | ||
return kNodeModulesRE.test(filename); | ||
if (Array.isArray(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.
Maybe just invert the conditional to make here?
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.
Yeah, I just wanted to keep the semantics exactly the same as before so return false;
after everything, even if it's strictly-speaking unreachable from the for loop.
if (!/^\/|\\/.test(filename)) | ||
continue; | ||
return kNodeModulesRE.test(filename); | ||
if (Array.isArray(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.
Is this sufficient to fix the original bug with ts-node? That was triggering at original line 360 with frame existing but getFileName being undefined, which is inside the for loop. That seems to imply to me that it would not be fixed by an Array.isArray check. I'm not sure how to grab this to confirm that though.
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.
Yeah, it's because if stack is not an array then it's a string so it iterates on individual characters which obviously don't have getFileName
.
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.
It might be good to throw in an extra check for the existence of getFileName
as a function
, just to be extra safe.
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.
Hmmm... but we do want to minimize how much work we do here. There are two possibilities here:
-
We call our own
prepareStackTrace
which returns an Array with the correct data. -
We are already in an error handling mode and just get the default stack trace which is a string, not an array.
There's no real alternative here. We can't end up calling a user-provided prepareStackTrace
or something similar. I did think about it before making this check.
node-test-commit-smartos re-run: https://ci.nodejs.org/job/node-test-commit-smartos/17152/ |
node-test-commit-aix re-run: https://ci.nodejs.org/job/node-test-commit-aix/14493/ |
Thanks everyone. Landed in 16aee38 |
When isInsideNodeModules gets called while already processing another stack trace, V8 will not call prepareStackTrace again. This used to cause Node.js to just crash — fix it by checking for expected return type of the stack (Array). PR-URL: #20266 Fixes: #20258 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
When isInsideNodeModules gets called while already processing another stack trace, V8 will not call prepareStackTrace again. This used to cause Node.js to just crash — fix it by checking for expected return type of the stack (Array). PR-URL: #20266 Fixes: #20258 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
When
isInsideNodeModules
gets called while already processinganother stack trace, V8 will not call
prepareStackTrace
again.This used to cause Node.js to just crash — fix it by checking
for expected return type of the stack (
Array
).Fixes: #20258
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes