MCPcopy Create free account
hub / github.com/QwikDev/qwik / formatError

Function formatError

packages/qwik/src/optimizer/src/plugins/vite-utils.ts:3–27  ·  view source on GitHub ↗
(sys: OptimizerSystem, e: Error)

Source from the content-addressed store, hash-verified

1import type { OptimizerSystem } from '../types';
2
3export async function formatError(sys: OptimizerSystem, e: Error) {
4 const err = e as any;
5 let loc = err.loc;
6
7 if (!err.frame && !err.plugin) {
8 if (!loc) {
9 loc = findLocation(err);
10 }
11 if (loc) {
12 err.loc = loc;
13 if (loc.file) {
14 const fs: typeof import('fs') = await sys.dynamicImport('node:fs');
15 const { normalizePath }: typeof import('vite') = await sys.dynamicImport('vite');
16 err.id = normalizePath(err.loc.file);
17 try {
18 const code = fs.readFileSync(err.loc.file, 'utf-8');
19 err.frame = generateCodeFrame(code, err.loc);
20 } catch {
21 // nothing
22 }
23 }
24 }
25 }
26 return e;
27}
28
29export interface Loc {
30 file: string;

Callers 2

getImageSizeServerFunction · 0.90
configureDevServerFunction · 0.90

Calls 3

findLocationFunction · 0.85
generateCodeFrameFunction · 0.85
normalizePathFunction · 0.70

Tested by

no test coverage detected