Skip to content

Commit

Permalink
chore(maintenance): drop support for Node.js 14 (#1802)
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamorosi committed Feb 5, 2024
1 parent 5665bf6 commit 99464d7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@
"engines": {
"node": ">=16"
}
}
}
23 changes: 20 additions & 3 deletions packages/logger/src/formatter/LogFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ import type {
import type { UnformattedAttributes } from '../types/Logger.js';
import { LogItem } from './LogItem.js';

/**
* Typeguard to monkey patch Error to add a cause property.
*
* This is needed because the `cause` property is present in ES2022 or newer.
* Since we want to be able to format errors in Node 16.x, we need to
* add this property ourselves. We can remove this once we drop support
* for Node 16.x.
*
* @see https://nodejs.org/api/errors.html#errors_error_cause
*/
const isErrorWithCause = (
error: Error
): error is Error & { cause: unknown } => {
return 'cause' in error;
};

/**
* This class defines and implements common methods for the formatting of log attributes.
*
Expand Down Expand Up @@ -49,10 +65,11 @@ abstract class LogFormatter implements LogFormatterInterface {
location: this.getCodeLocation(error.stack),
message: error.message,
stack: error.stack,
cause:
error.cause instanceof Error
cause: isErrorWithCause(error)
? error.cause instanceof Error
? this.formatError(error.cause)
: error.cause,
: error.cause
: undefined,
};
}

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"incremental": true,
"composite": true,
"target": "ES2022", // Node.js 16
"target": "ES2021", // Node.js 16
"experimentalDecorators": true,
"module": "commonjs",
"moduleResolution": "node",
Expand Down

0 comments on commit 99464d7

Please sign in to comment.