Skip to content

Commit

Permalink
fix: throw SfError from catch (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Feb 23, 2023
1 parent 5a52aa1 commit 1eb1c17
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/sfCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ export abstract class SfCommand<T> extends Command {
context: (error.context as string) ?? null,
});

// Create printable error object
const sfCommandError: SfCommand.Error = {
...sfErrorProperties,
...{
Expand All @@ -464,7 +465,22 @@ export abstract class SfCommand<T> extends Command {
this.logToStderr(this.formatError(sfCommandError));
}

throw sfCommandError;
// Create SfError that can be thrown
const err = new SfError(
error.message,
error.name ?? 'Error',
// @ts-expect-error because actions is not on Error
(error.actions as string[]) ?? [],
process.exitCode
);
err.context = sfCommandError.context;
err.stack = sfCommandError.stack;
// @ts-expect-error because code is not on SfError
err.code = codeFromError;
// @ts-expect-error because code is not on SfError
err.status = sfCommandError.status;

throw err;
}

/**
Expand Down

0 comments on commit 1eb1c17

Please sign in to comment.