From 8abd3a47f5a4690c0e1cf9b9730fa7ab0a3ef05c Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Thu, 23 Feb 2023 09:48:46 -0700 Subject: [PATCH] fix: throw SfError from catch --- src/sfCommand.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/sfCommand.ts b/src/sfCommand.ts index 9d3d4871..ebad8c88 100644 --- a/src/sfCommand.ts +++ b/src/sfCommand.ts @@ -447,6 +447,7 @@ export abstract class SfCommand extends Command { context: (error.context as string) ?? null, }); + // Create printable error object const sfCommandError: SfCommand.Error = { ...sfErrorProperties, ...{ @@ -464,7 +465,22 @@ export abstract class SfCommand 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.stack = error.stack; + 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; } /**