Skip to content

Commit 99464d7

Browse files
committed
chore(maintenance): drop support for Node.js 14 (#1802)
1 parent 5665bf6 commit 99464d7

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@
7676
"engines": {
7777
"node": ">=16"
7878
}
79-
}
79+
}

Diff for: packages/logger/src/formatter/LogFormatter.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ import type {
77
import type { UnformattedAttributes } from '../types/Logger.js';
88
import { LogItem } from './LogItem.js';
99

10+
/**
11+
* Typeguard to monkey patch Error to add a cause property.
12+
*
13+
* This is needed because the `cause` property is present in ES2022 or newer.
14+
* Since we want to be able to format errors in Node 16.x, we need to
15+
* add this property ourselves. We can remove this once we drop support
16+
* for Node 16.x.
17+
*
18+
* @see https://nodejs.org/api/errors.html#errors_error_cause
19+
*/
20+
const isErrorWithCause = (
21+
error: Error
22+
): error is Error & { cause: unknown } => {
23+
return 'cause' in error;
24+
};
25+
1026
/**
1127
* This class defines and implements common methods for the formatting of log attributes.
1228
*
@@ -49,10 +65,11 @@ abstract class LogFormatter implements LogFormatterInterface {
4965
location: this.getCodeLocation(error.stack),
5066
message: error.message,
5167
stack: error.stack,
52-
cause:
53-
error.cause instanceof Error
68+
cause: isErrorWithCause(error)
69+
? error.cause instanceof Error
5470
? this.formatError(error.cause)
55-
: error.cause,
71+
: error.cause
72+
: undefined,
5673
};
5774
}
5875

Diff for: tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"incremental": true,
44
"composite": true,
5-
"target": "ES2022", // Node.js 16
5+
"target": "ES2021", // Node.js 16
66
"experimentalDecorators": true,
77
"module": "commonjs",
88
"moduleResolution": "node",

0 commit comments

Comments
 (0)