Skip to content

Commit d19f28e

Browse files
committed
fix: use native ES2022 error cause (#5010)
This improves error messages and stack traces. For example: Before: Error at new SubprocessError (.../dist/index.js:41:23) at ChildProcess.<anonymous> (.../dist/index.js:125:27) at ChildProcess.emit (node:events:513:28) at maybeClose (node:internal/child_process:1100:16) at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5) After: SubprocessError: Signal exit from subprocess. at ChildProcess.<anonymous> (.../dist/index.js:122:27) at ChildProcess.emit (node:events:513:28) at maybeClose (node:internal/child_process:1100:16) at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5) { code: 'ERR_SUBPROCESS_SIGNAL_EXIT', signal: 'SIGTERM' }
1 parent a97ba2b commit d19f28e

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ 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';
67

78
import { IonicNamespace } from './commands';
89
import { IPCMessage, IonicContext, IonicEnvironment } from './definitions';
@@ -171,11 +172,7 @@ export async function run(pargv: string[]): Promise<void> {
171172
} else if (err instanceof BaseError) {
172173
ienv.log.error(err.message);
173174
} else {
174-
ienv.log.msg(failure(String(err.stack ? err.stack : err)));
175-
176-
if (err.stack) {
177-
debug(failure(String(err.stack)));
178-
}
175+
ienv.log.rawmsg(failure(util.inspect(err)));
179176
}
180177
}
181178
}

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-
readonly error?: Error
58+
cause?: Error
5959
) {
60-
super(msg);
60+
super(msg, { cause });
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.error ? `${e1.message}: ${failure(e1.error.toString())}` : failure(e1.message)}. ` +
196+
`${e1.cause ? `${e1.message}: ${failure(e1.cause.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

0 commit comments

Comments
 (0)