From 2190a6130a7e2188df5ef7e9f86ca92179241420 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Fri, 15 Nov 2024 16:24:21 -0600 Subject: [PATCH 1/2] fix: don't destructure error object --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 66da1d0..c20ddee 100644 --- a/src/index.ts +++ b/src/index.ts @@ -126,7 +126,7 @@ export async function captureOutput(fn: () => Promise, opts?: Captur } catch (error) { return { ...(error instanceof Errors.CLIError && {error: {...error, message: toString(error.message)}}), - ...(error instanceof Error && {error: {...error, message: toString(error.message)}}), + ...(error instanceof Error && {error}), stderr: getStderr(), stdout: getStdout(), } From 2acb94574380d785fff854b42019f70cab42a63a Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Sat, 16 Nov 2024 18:29:28 -0600 Subject: [PATCH 2/2] refactor: `Object.assign()` is the move here --- src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index c20ddee..3e13274 100644 --- a/src/index.ts +++ b/src/index.ts @@ -125,8 +125,8 @@ export async function captureOutput(fn: () => Promise, opts?: Captur } } catch (error) { return { - ...(error instanceof Errors.CLIError && {error: {...error, message: toString(error.message)}}), - ...(error instanceof Error && {error}), + ...(error instanceof Errors.CLIError && {error: Object.assign(error, {message: toString(error.message)})}), + ...(error instanceof Error && {error: Object.assign(error, {message: toString(error.message)})}), stderr: getStderr(), stdout: getStdout(), }