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
This commit is contained in:
Iain Sproat
2025-03-12 11:31:25 +00:00
parent 70a30e0795
commit 0ac69bc54b
+5 -1
View File
@@ -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