Skip to content

Commit

Permalink
fix: use native ES2022 error cause (#5010)
Browse files Browse the repository at this point in the history
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'
}
  • Loading branch information
ltm committed Nov 8, 2023
1 parent a97ba2b commit d19f28e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
7 changes: 2 additions & 5 deletions packages/@ionic/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { readPackageJsonFile } from '@ionic/cli-framework/utils/node';
import { processExit } from '@ionic/utils-process';
import * as Debug from 'debug';
import * as path from 'path';
import * as util from 'util';

import { IonicNamespace } from './commands';
import { IPCMessage, IonicContext, IonicEnvironment } from './definitions';
Expand Down Expand Up @@ -171,11 +172,7 @@ export async function run(pargv: string[]): Promise<void> {
} else if (err instanceof BaseError) {
ienv.log.error(err.message);
} else {
ienv.log.msg(failure(String(err.stack ? err.stack : err)));

if (err.stack) {
debug(failure(String(err.stack)));
}
ienv.log.rawmsg(failure(util.inspect(err)));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/@ionic/cli/src/lib/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ export class ProjectDetailsError extends BaseException {
/**
* The underlying error that caused this error.
*/
readonly error?: Error
cause?: Error
) {
super(msg);
super(msg, { cause });
}
}

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

Expand Down

0 comments on commit d19f28e

Please sign in to comment.