From 1eb1c1715ceef59ee424677a351607ae0568b513 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Thu, 23 Feb 2023 12:13:46 -0800 Subject: [PATCH] fix: throw SfError from catch (#230) --- src/sfCommand.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/sfCommand.ts b/src/sfCommand.ts index 9d3d4871..cf460eae 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.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; } /**