Skip to content

Commit a97ba2b

Browse files
committed
fix: use native ES2022 error cause (#5010)
BREAKING CHANGE: `message`, `stack`, and `error` properties removed from `BaseError` and `SubprocessError`
1 parent b06ab3c commit a97ba2b

File tree

3 files changed

+5
-29
lines changed

3 files changed

+5
-29
lines changed

packages/@ionic/cli-framework/src/errors.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as lodash from 'lodash';
21
import * as util from 'util';
32

43
import { ValidationError } from './definitions';
@@ -10,25 +9,11 @@ export const ERROR_IPC_UNKNOWN_PROCEDURE = 'ERR_ICF_IPC_UNKNOWN_PROCEDURE';
109

1110
export abstract class BaseError extends Error {
1211
abstract readonly name: string;
13-
message: string;
14-
stack: string;
1512
code?: string;
16-
error?: Error;
1713
exitCode?: number;
1814

19-
constructor(message: string) {
20-
super(message);
21-
this.message = message;
22-
this.stack = (new Error()).stack || '';
23-
}
24-
2515
toString(): string {
26-
const repr = lodash.pick(this, lodash.pull(lodash.keys(this), 'error'));
27-
28-
return (
29-
`${this.name}: ${this.message} ${util.inspect(repr, { breakLength: Infinity })} ${this.stack} ` +
30-
`${this.error ? `\nWrapped: ${this.error.stack ? this.error.stack : this.error}` : ''}`
31-
);
16+
return util.inspect(this);
3217
}
3318

3419
inspect(): string {

packages/@ionic/utils-subprocess/src/index.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,11 @@ export function convertPATH(path = process.env.PATH || ''): string {
3535

3636
export class SubprocessError extends Error {
3737
readonly name = 'SubprocessError';
38-
message: string;
39-
stack: string;
4038

4139
code?: typeof ERROR_COMMAND_NOT_FOUND | typeof ERROR_NON_ZERO_EXIT | typeof ERROR_SIGNAL_EXIT;
42-
error?: Error;
4340
output?: string;
4441
signal?: string;
4542
exitCode?: number;
46-
47-
constructor(message: string) {
48-
super(message);
49-
this.message = message;
50-
this.stack = (new Error()).stack || '';
51-
}
5243
}
5344

5445
export interface SubprocessOptions extends SpawnOptions {}
@@ -172,13 +163,12 @@ export class Subprocess {
172163
let err: SubprocessError;
173164

174165
if (error.code === 'ENOENT') {
175-
err = new SubprocessError('Command not found.');
166+
err = new SubprocessError('Command not found.', { cause: error });
176167
err.code = ERROR_COMMAND_NOT_FOUND;
177168
} else {
178-
err = new SubprocessError('Command error.');
169+
err = new SubprocessError('Command error.', { cause: error });
179170
}
180171

181-
err.error = error;
182172
reject(err);
183173
});
184174

tsconfig.base.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"target": "ES2021",
1313
"types": [],
1414
"lib": [
15-
"ES2021"
15+
"ES2021",
16+
"ES2022.Error"
1617
]
1718
}
1819
}

0 commit comments

Comments
 (0)