Added the requireStack to loader.js#45734
Conversation
|
Review requested:
|
lib/internal/modules/cjs/loader.js
Outdated
There was a problem hiding this comment.
I think @BridgeAR's comment was referring to the requireStack that's generated in
node/lib/internal/modules/cjs/loader.js
Lines 1027 to 1032 in 7811d2d
new Error().stack produces.
|
Do we add arbitrary properties to |
Yes, e.g. every error from a Node.js API has a |
aduh95
left a comment
There was a problem hiding this comment.
What is the use case that's would be fixed by it? I think we should start with writing some tests for the feature so we set the expectations for what we want the feature to look like, and then proceed with the implementation. Adding an empty array to an error object doesn't make much sense to me if I can't see in what context it can be used, having tests for that would help greatly.
|
The use case for this property has been discussed in #25690. As suggested in #45734 (comment), this array should be populated with paths of non-internal modules that are present in the stack trace. |
lib/internal/modules/cjs/loader.js
Outdated
There was a problem hiding this comment.
This function is a hook for users to register their own stack trace customizations. I’m not sure we should be using it internally.
test/parallel/test-loader.js
Outdated
There was a problem hiding this comment.
This can be tested using the public APIs alone, so I would suggest you to revert the tryPackage exporting change from lib/internal/modules/cjs/loader.js and instead create a temporary file structure of this sort dynamically while running the test:
❯ tree -a
.
├── index.js
└── node_modules
├── a
│ ├── a.js
│ └── package.json
└── b
└── package.json
3 directories, 4 files
❯ cat index.js
require('a');
❯ cat node_modules/a/a.js
require('b');
❯ cat node_modules/a/package.json
{
"main": "a.js"
}
❯ cat node_modules/b/package.json
{
"main": "b.js"
}and assert on the requireStack property of the error thrown by the index.js file.
Also, note that this is a CJS file, so the way you used import here won't work.
test/parallel/test-loader.js
Outdated
There was a problem hiding this comment.
test-loader.js is a much too generic name. test-require-package-errors.js perhaps?
Or even better, find where we currently test the errors potentially thrown by require and add your new cases there.
test/parallel/test-loader.js
Outdated
There was a problem hiding this comment.
Surely there’s an existing test that require of a package works?
lib/internal/modules/cjs/loader.js
Outdated
There was a problem hiding this comment.
Nit: line lengths here should be <= 100 chars.
|
uh 🆘 |
|
I can't re-open it 🤨 |
|
I guess it cannot be reopened since it has no commits |
|
I'm so sorry I accidentally blew my code here :( |
// TODO(BridgeAR): Add the requireStack as well.
I also added the require stack