Hardened JavaScript interferes with Node.js 14 Error construction
See original GitHub issue@warner reports:
Then I used fs.openReadStream(undefined) (not intentionally, I forgot to provide argv). The error I get is T
ypeError#1: Cannot assign to read only property 'name' of object 'TypeError: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined'
the stack trace includes:at addCodeToName (internal/errors.js:329:12) at new NodeError (internal/errors.js:294:7) at internal/fs/utils.js:634:11
The relevant code in Node.js 14.17.4 is:
function addCodeToName(err, name, code) {
// Set the stack
if (excludedStackFn !== undefined) {
ErrorCaptureStackTrace(err, excludedStackFn);
}
// Add the error code to the name to include it in the stack trace.
err.name = `${name} [${code}]`;
// Access the stack to generate the error message including the error code
// from the name.
err.stack; // eslint-disable-line no-unused-expressions
// Reset the name to the actual name.
if (name === 'SystemError') {
ObjectDefineProperty(err, 'name', {
value: name,
enumerable: false,
writable: true,
configurable: true
});
} else {
delete err.name;
}
}
And the culprit is the property override hazard, upon assigning to name
of an instance descended from a frozen error constructor.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Best Practices for Node.js Error-handling - Toptal
Developers working with Node.js sometimes find themselves writing not-so-clean code while handling all sorts of errors. This article will introduce you to ...
Read more >Node.js Error Handling Best Practices - Sematext
Learn what is Node.js error handling and why do you need it. From using middleware to catching uncaught exceptions, discover the best ways ......
Read more >error: This is probably not a problem with npm. There is likely ...
For me, it happens because of the low version of Node. Upload my Node version and it worked successfully.
Read more >Errors | Node.js v19.3.0 Documentation
All JavaScript errors are handled as exceptions that immediately generate ... An invalid parameter key was passed during construction of a Brotli stream....
Read more >15 Common Error Codes in Node.js and How to Fix Them
Therefore, we've compiled this list of 15 common Node.js errors along ... up at connResetException (node:internal/errors:691:14) at Socket.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@kriskowal This does not have an area label that is covered by our weekly tech / planning meetings. Can you assign the proper label? We cover: agd, agoric-cosmos, amm, core economy, cosmic-swingset, endo, getrun, governance, installation-bundling, metering, run-protocol, staking, swingset, swingset-runner, token economy, wallet, zoe contract,
Well, we could trivially copy this
moderate
change so it applies tomin
too. I don’t like it, but Node…Have we told Node about this? Have we filed an issue? Is it still a problem on Node 16?