(sys: OptimizerSystem, e: Error)
| 1 | import type { OptimizerSystem } from '../types'; |
| 2 | |
| 3 | export 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 | |
| 29 | export interface Loc { |
| 30 | file: string; |
no test coverage detected