question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 TypeError#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:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Tartuffocommented, Feb 3, 2022

@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,

0reactions
erightscommented, Feb 3, 2022

Well, we could trivially copy this moderate change so it applies to min 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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found