From 03c7cf695903352f9feedd5195e529fc053b4443 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 9 Jun 2022 18:32:36 +0300 Subject: [PATCH] fix: don't fail when there is no source file defined in source map (#1453) * fix: don't fail when there is no source file, defined in source map * chore: cleanup --- packages/vitest/src/node/error.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/vitest/src/node/error.ts b/packages/vitest/src/node/error.ts index f92d23e1c1d0..afb1d4123994 100644 --- a/packages/vitest/src/node/error.ts +++ b/packages/vitest/src/node/error.ts @@ -50,8 +50,13 @@ export async function printError(error: unknown, ctx: Vitest, options: PrintErro printErrorMessage(e, ctx.console) printStack(ctx, stacks, nearest, errorProperties, (s, pos) => { if (showCodeFrame && s === nearest && nearest) { - const sourceCode = readFileSync(fileFromParsedStack(nearest), 'utf-8') - ctx.log(c.yellow(generateCodeFrame(sourceCode, 4, pos))) + const file = fileFromParsedStack(nearest) + // could point to non-existing original file + // for example, when there is a source map file, but no source in node_modules + if (existsSync(file)) { + const sourceCode = readFileSync(file, 'utf-8') + ctx.log(c.yellow(generateCodeFrame(sourceCode, 4, pos))) + } } })