diff --git a/src/core.ts b/src/core.ts index 6b59935..5d652d0 100644 --- a/src/core.ts +++ b/src/core.ts @@ -978,6 +978,11 @@ const validatePositiveInteger = (name: string, n: unknown): number => { export const castToError = (err: any): Error => { if (err instanceof Error) return err; + if (typeof err === 'object' && err !== null) { + try { + return new Error(JSON.stringify(err)); + } catch {} + } return new Error(err); };