From bd677017d965922ccce7ca533b13baeb681d3c51 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Wed, 5 Oct 2022 14:57:58 +0200 Subject: [PATCH] fix: don't stop watch mode, if non-object error is thrown, close #2106 --- packages/vitest/src/node/error.ts | 8 ++++++++ packages/vitest/src/utils/source-map.ts | 3 +++ 2 files changed, 11 insertions(+) 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