Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: preserve oclif exit code #460

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/sfCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ export abstract class SfCommand<T> extends Command {
// transform an unknown error into one that conforms to the interface

// @ts-expect-error because exitCode is not on Error
const codeFromError = (error.exitCode as number) ?? 1;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
const codeFromError = (error.exitCode as number | undefined) ?? (error.oclif?.exit as number | undefined) ?? 1;
mshanemc marked this conversation as resolved.
Show resolved Hide resolved
process.exitCode ??= codeFromError;

const sfErrorProperties = removeEmpty({
Expand Down Expand Up @@ -476,6 +477,10 @@ export abstract class SfCommand<T> extends Command {
// @ts-expect-error because skipOclifErrorHandling is not on SfError
err.skipOclifErrorHandling = true;

// Add oclif exit code to the error so that oclif can use the exit code when exiting.
// @ts-expect-error because oclif is not on SfError
err.oclif = { exit: process.exitCode };

// Emit an event for plugin-telemetry prerun hook to pick up.
// @ts-expect-error because TS is strict about the events that can be emitted on process.
process.emit('sfCommandError', err);
Expand Down
Loading