Skip to content

Commit 1e64a1a

Browse files
authored
revert: use native ES2022 error cause (#5060)
This reverts commit 0c4cd0f.
1 parent b0af2be commit 1e64a1a

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as lodash from 'lodash';
12
import * as util from 'util';
23

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

1011
export abstract class BaseError extends Error {
1112
abstract readonly name: string;
13+
message: string;
14+
stack: string;
1215
code?: string;
16+
error?: Error;
1317
exitCode?: number;
1418

19+
constructor(message: string) {
20+
super(message);
21+
this.message = message;
22+
this.stack = (new Error()).stack || '';
23+
}
24+
1525
toString(): string {
16-
return util.inspect(this);
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+
);
1732
}
1833

1934
inspect(): string {

packages/@ionic/cli/src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { readPackageJsonFile } from '@ionic/cli-framework/utils/node';
33
import { processExit } from '@ionic/utils-process';
44
import * as Debug from 'debug';
55
import * as path from 'path';
6-
import * as util from 'util';
76

87
import { IonicNamespace } from './commands';
98
import { IPCMessage, IonicContext, IonicEnvironment } from './definitions';
@@ -172,7 +171,11 @@ export async function run(pargv: string[]): Promise<void> {
172171
} else if (err instanceof BaseError) {
173172
ienv.log.error(err.message);
174173
} else {
175-
ienv.log.rawmsg(failure(util.inspect(err)));
174+
ienv.log.msg(failure(String(err.stack ? err.stack : err)));
175+
176+
if (err.stack) {
177+
debug(failure(String(err.stack)));
178+
}
176179
}
177180
}
178181
}

packages/@ionic/cli/src/lib/project/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ export class ProjectDetailsError extends BaseException {
5555
/**
5656
* The underlying error that caused this error.
5757
*/
58-
cause?: Error
58+
readonly error?: Error
5959
) {
60-
super(msg, { cause });
60+
super(msg);
6161
}
6262
}
6363

@@ -193,7 +193,7 @@ export class ProjectDetails {
193193
if (e1) {
194194
log.error(
195195
`Error while loading config (project config: ${strong(prettyPath(result.configPath))})\n` +
196-
`${e1.cause ? `${e1.message}: ${failure(e1.cause.toString())}` : failure(e1.message)}. ` +
196+
`${e1.error ? `${e1.message}: ${failure(e1.error.toString())}` : failure(e1.message)}. ` +
197197
`Run ${input('ionic init')} to re-initialize your Ionic project. Without a valid project config, the CLI will not have project context.`
198198
);
199199

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,20 @@ 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;
3840

3941
code?: typeof ERROR_COMMAND_NOT_FOUND | typeof ERROR_NON_ZERO_EXIT | typeof ERROR_SIGNAL_EXIT;
42+
error?: Error;
4043
output?: string;
4144
signal?: string;
4245
exitCode?: number;
46+
47+
constructor(message: string) {
48+
super(message);
49+
this.message = message;
50+
this.stack = (new Error()).stack || '';
51+
}
4352
}
4453

4554
export interface SubprocessOptions extends SpawnOptions {}
@@ -163,12 +172,13 @@ export class Subprocess {
163172
let err: SubprocessError;
164173

165174
if (error.code === 'ENOENT') {
166-
err = new SubprocessError('Command not found.', { cause: error });
175+
err = new SubprocessError('Command not found.');
167176
err.code = ERROR_COMMAND_NOT_FOUND;
168177
} else {
169-
err = new SubprocessError('Command error.', { cause: error });
178+
err = new SubprocessError('Command error.');
170179
}
171180

181+
err.error = error;
172182
reject(err);
173183
});
174184

tsconfig.base.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
"target": "ES2021",
1313
"types": [],
1414
"lib": [
15-
"ES2021",
16-
"ES2022.Error"
15+
"ES2021"
1716
]
1817
}
1918
}

0 commit comments

Comments
 (0)