Skip to content

Commit 4a6fb33

Browse files
authored
fix!: use spec Error.cause property instead of legacy cause() function (#112)
* fix!: use spec Error.cause property instead of legacy cause() function @netflix/nerror@2.0.0-rc.0 replaces the non-standard cause() method with the native Error.cause property. Update HttpError.toJSON() and the serializer's cause-chain walk accordingly, and fix a latent bug where toJSON() was serializing the cause function reference itself rather than a value. BREAKING CHANGE: Error instances no longer expose .cause() as a callable function. Consumers must access the spec-compliant .cause property instead. Bump @netflix/nerror dependency/override to ^2.0.0-rc.0 and package version to 9.0.0-rc.0 accordingly. * deps: bump restify, restify-clients, and @netflix/nerror Also update CI to test Node 24/26 only and declare engines >=24, since @netflix/nerror@2.0.0 requires Node >=24.
1 parent f31ef54 commit 4a6fb33

7 files changed

Lines changed: 154 additions & 342 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
node-version: [18, 20, 22]
12+
node-version: [24, 26]
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v7
@@ -21,22 +21,3 @@ jobs:
2121
run: npm ci
2222
- name: Test / Lint / Codestyle
2323
run: make all
24-
test-optional:
25-
runs-on: ubuntu-latest
26-
strategy:
27-
fail-fast: false
28-
matrix:
29-
node-version: [24]
30-
steps:
31-
- name: Checkout
32-
uses: actions/checkout@v7
33-
- name: Setup Node.js
34-
uses: actions/setup-node@v7
35-
with:
36-
node-version: ${{ matrix.node-version }}
37-
- name: Install
38-
run: npm ci
39-
continue-on-error: true
40-
- name: Test / Lint / Codestyle
41-
run: make all
42-
continue-on-error: true

‎CHANGES.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change log
22

3+
## 9.0.0-rc.0
4+
5+
- BREAKING: upgrade to `@netflix/nerror@2.0.0-rc.0`, which drops the legacy
6+
`.cause()` function in favor of the spec `Error.prototype.cause` property.
7+
`lib/serializer.js` and `lib/baseClasses/HttpError.js` now read `err.cause`
8+
as a property instead of invoking it as a function.
9+
310
## 7.0.0
411

512
- BREAKING: omit node domains from serializer

‎lib/baseClasses/HttpError.js‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ HttpError.prototype.toJSON = function toJSON() {
149149
var message = '';
150150

151151
// if we have a cause, get the full VError toString() without the current
152-
// error name. verbose check, self.cause can exist but returns undefined
153-
if (self.cause && typeof self.cause === 'function' && self.cause()) {
152+
// error name.
153+
if (self.cause) {
154154
var fullString = self.toString();
155155
message = fullString.substr(fullString.indexOf(' ') + 1);
156156
} else {
@@ -159,8 +159,7 @@ HttpError.prototype.toJSON = function toJSON() {
159159

160160
return {
161161
code: self.body.code,
162-
message: message,
163-
cause: self.cause
162+
message: message
164163
};
165164
};
166165

‎lib/serializer.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function _getMultiErrorStack(err) {
7171

7272

7373
/**
74-
* loop through all cause() errors and build a stack trace output
74+
* loop through all cause errors and build a stack trace output
7575
* @private
7676
* @method _getFullErrorStack
7777
* @param {Object} err an error object
@@ -94,7 +94,7 @@ function _getFullErrorStack(err) {
9494

9595
out += stackString.shift() + self._getSerializedContext(e);
9696
out += stackString.join('\n');
97-
e = (typeof e.cause === 'function') ? e.cause() : null;
97+
e = e.cause || null;
9898
first = false;
9999
} while (e);
100100

0 commit comments

Comments
 (0)