Skip to content

Commit

Permalink
fix: error can't be spread
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jun 6, 2022
1 parent b566b4a commit 30930b7
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/sfCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,19 @@ export abstract class SfCommand<T> extends Command {
// transform an unknown error into one that conforms to the interface
const codeFromError = error instanceof SfError ? error.exitCode : 1;
process.exitCode ??= codeFromError;
const sfCommandError = {
...error,
status: process.exitCode,
stack: error.stack,
const sfErrorProperties =
error instanceof SfError
? { data: error.data, actions: error.actions, code: codeFromError, context: error.context }
: {};
const sfCommandError: SfCommand.Error = {
...sfErrorProperties,
...{
message: error.message,
name: error.name ?? 'Error',
status: process.exitCode,
stack: error.stack,
exitCode: process.exitCode,
},
};

if (this.jsonEnabled()) {
Expand Down Expand Up @@ -341,5 +350,6 @@ export namespace SfCommand {
code?: unknown;
exitCode?: number;
data?: unknown;
context?: string;
}
}

0 comments on commit 30930b7

Please sign in to comment.