AriaMinaei / pretty-error

See node.js errors with less clutter
MIT License
1.52k stars 49 forks source link

PrettyError.skipNodeFiles() doesn't appear to work #59

Open lachieh opened 3 years ago

lachieh commented 3 years ago

Not sure if paths changed since previous Node versions, or if this method was only intended to include specific files but it doesn't seem to be working the way I would expect this to work.

For example, I would consider the internal/modules/cjs/loader.js file to be a Node file since I didn't create it but even when I set up this basic script, the trace still shows that file:

const PrettyError = require('pretty-error');
const pe = new PrettyError();
pe.skipNodeFiles();
pe.start();

console.log(processs.cwd()) // misspelled to cause error
Console Output ``` [ ReferenceError: processs is not defined - server.js:35 Object. [project]/server-express/server.js:35:13 - loader.js:1063 Module._compile internal/modules/cjs/loader.js:1063:30 - loader.js:1092 Object.Module._extensions..js internal/modules/cjs/loader.js:1092:10 - loader.js:928 Module.load internal/modules/cjs/loader.js:928:32 - loader.js:769 Function.Module._load internal/modules/cjs/loader.js:769:14 - loader.js:952 Module.require internal/modules/cjs/loader.js:952:19 - helpers.js:88 require internal/modules/cjs/helpers.js:88:18 - www:7 Object. ./bin/www:7:13 - loader.js:1063 Module._compile internal/modules/cjs/loader.js:1063:30 - loader.js:1092 Object.Module._extensions..js internal/modules/cjs/loader.js:1092:10 ] ```

I'm pretty sure that this is because the nodePaths.coffee references exact filenames, and the relevant code is just using indexOf to check if the stack path is a "Node" file.

I'll add that I'm making a lot of assumptions here, so apologies if I'm misunderstanding the skipNodeFiles method or anything else.

Thanks for all the work on the project so far!

willroberts commented 2 years ago

I've worked around this by setting some node:internal paths independently:

pe.skipPath('node:internal/main/run_main_module')
pe.skipPath('node:internal/modules/cjs/helpers')
pe.skipPath('node:internal/modules/cjs/loader')
pe.skipPath('node:internal/modules/run_main')
// etc.