Skip to content

Commit ab12feb

Browse files
greg84stainless-app[bot]
authored andcommitted
chore: better object fallback behaviour for casting errors (#503)
1 parent b7e2113 commit ab12feb

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/core.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,12 @@ const validatePositiveInteger = (name: string, n: unknown): number => {
994994

995995
export const castToError = (err: any): Error => {
996996
if (err instanceof Error) return err;
997-
return new Error(err);
997+
if (typeof err === 'object' && err !== null) {
998+
try {
999+
return new Error(JSON.stringify(err));
1000+
} catch {}
1001+
}
1002+
return new Error(String(err));
9981003
};
9991004

10001005
export const ensurePresent = <T>(value: T | null | undefined): T => {

0 commit comments

Comments
 (0)