diff --git a/packages/vitest/src/node/error.ts b/packages/vitest/src/node/error.ts index d6a60504b2d0..aea8b0c4dd5b 100644 --- a/packages/vitest/src/node/error.ts +++ b/packages/vitest/src/node/error.ts @@ -35,6 +35,14 @@ export async function printError(error: unknown, ctx: Vitest, options: PrintErro } as any } + if (!e) { + const error = new Error('unknown error') + e = { + message: e ?? error.message, + stack: error.stack, + } as any + } + const stacks = parseStacktrace(e, fullStack) await interpretSourcePos(stacks, ctx) diff --git a/packages/vitest/src/utils/source-map.ts b/packages/vitest/src/utils/source-map.ts index 7ae41a9389f0..e4b734790eae 100644 --- a/packages/vitest/src/utils/source-map.ts +++ b/packages/vitest/src/utils/source-map.ts @@ -57,6 +57,9 @@ function extractLocation(urlLike: string) { } export function parseStacktrace(e: ErrorWithDiff, full = false): ParsedStack[] { + if (!e) + return [] + if (e.stacks) return e.stacks