From 0ac69bc54bad91f4eff8965ee2c6a6fa1e4525f3 Mon Sep 17 00:00:00 2001 From: Iain Sproat <68657+iainsproat@users.noreply.github.com> Date: Wed, 12 Mar 2025 11:31:25 +0000 Subject: [PATCH] fix(shared): ensureError should not bury original message - if 'e', the original cause, is not an Error, it is buried by the fallback message. - this PR ensures that the original cause is included in the error message --- packages/shared/src/core/helpers/error.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/shared/src/core/helpers/error.ts b/packages/shared/src/core/helpers/error.ts index 3a16cdd16..2948c41f3 100644 --- a/packages/shared/src/core/helpers/error.ts +++ b/packages/shared/src/core/helpers/error.ts @@ -9,7 +9,11 @@ export function ensureError( fallbackMessage?: string ): Error | UnexpectedErrorStructureError { if (e instanceof Error) return e - return new UnexpectedErrorStructureError(fallbackMessage) + return new UnexpectedErrorStructureError( + `${fallbackMessage}${ + e !== null && e !== undefined ? `Cause: ${JSON.stringify(e)}` : '' + }` + ) } // this makes sure that a case is breaking in typing and in runtime too