Skip to content

fix(verror)!: make cause a spec-compliant property - #21

Open
mason-albert wants to merge 4 commits into
masterfrom
masona/fix-cause-spec
Open

fix(verror)!: make cause a spec-compliant property#21
mason-albert wants to merge 4 commits into
masterfrom
masona/fix-cause-spec

Conversation

@mason-albert

@mason-albert mason-albert commented Jul 28, 2026

Copy link
Copy Markdown
  • Make VError/WError's cause, spec-compliant instance property (non-enumerable, writable, configurable) instead of a callable function. Breaking: err.cause() no longer works. use err.cause instead
  • Upgrade tsd to ^0.33.0 to fix type-checking against @types/node (the old bundled TypeScript compiler couldn't parse it)
  • Add an engines floor (node >=20) so incompatible transitive dependency resolution fails clearly instead of breaking installs unpredictably

VError.prototype.cause and WError.prototype.cause were function-style
accessors predating the language's native Error.cause. Replace them
with an instance property matching the native Error.cause with a
real, non-enumerable, writable instance property set on construction
(writable, non-enumerable, configurable).

Updates lib/index.d.ts, api.md, and all test call sites accordingly.

BREAKING CHANGE: err.cause() and err.cause(newCause) are no longer
callable. Use err.cause to read the cause, and pass { cause } to the
constructor to set it. WError's cause setter form is removed for the
same reason.
tsd@0.7.x bundles typescript@^3.0.1, too old to parse current
@types/node syntax, causing thousands of errors. Upgrading to
tsd@^0.33.0 fixes this and surfaces a few real type-test
inaccuracies, also fixed here.
nerror has no committed lockfile, so installs can pull transitive
deps that require newer Node (e.g. brace-expansion@5) and fail
unpredictably. Declaring an engines floor surfaces this explicitly.

This feels reasonable as nerror 2.0.0 is not expected to be used
or work with node versions older than 20.
@mason-albert
mason-albert force-pushed the masona/fix-cause-spec branch from 7be0d1a to b9bcc18 Compare July 28, 2026 17:33
Comment thread lib/verror.js
if (cause) {
VError._assertError(cause, '"cause" must be an Error');
this.jse_cause = cause;
Object.defineProperty(this, 'cause', {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's reasonable to replace jse_cause and not maintain 2 identical props w/ different names, since this is breaking anyway. That being said, I'm not sure if jse_cause is used directly somewhere, or if there's value in keeping it

@ondrej-kvasnovsky ondrej-kvasnovsky Jul 28, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I don't have the full context) It seems jse_cause is used (as a concept) in other repos: https://sourcegraph.netflix.io/search?q=context:global+jse_cause&patternType=keyword&sm=0 (so I would say it should stay and could be marked as deprecated?)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed you increased the version to 2.x... so ignore the deprecation note, I just wonder why was jse_cause created 🤔

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think nerror was based on verror, which used things like jse_cause, jse_info, etc. for a number of things. Unfortunately that's all the context I have 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants