({
error
}: Props)
| 26 | readonly error: Error; |
| 27 | }; |
| 28 | export default function ErrorOverview({ |
| 29 | error |
| 30 | }: Props) { |
| 31 | const stack = error.stack ? error.stack.split('\n').slice(1) : undefined; |
| 32 | const origin = stack ? getStackUtils().parseLine(stack[0]!) : undefined; |
| 33 | const filePath = cleanupPath(origin?.file); |
| 34 | let excerpt: CodeExcerpt[] | undefined; |
| 35 | let lineWidth = 0; |
| 36 | if (filePath && origin?.line) { |
| 37 | try { |
| 38 | // eslint-disable-next-line custom-rules/no-sync-fs -- sync render path; error overlay can't go async without suspense restructuring |
| 39 | const sourceCode = readFileSync(filePath, 'utf8'); |
| 40 | excerpt = codeExcerpt(sourceCode, origin.line); |
| 41 | if (excerpt) { |
| 42 | for (const { |
| 43 | line |
| 44 | } of excerpt) { |
| 45 | lineWidth = Math.max(lineWidth, String(line).length); |
| 46 | } |
| 47 | } |
| 48 | } catch { |
| 49 | // file not readable — skip source context |
| 50 | } |
| 51 | } |
| 52 | return <Box flexDirection="column" padding={1}> |
| 53 | <Box> |
| 54 | <Text backgroundColor="ansi:red" color="ansi:white"> |
| 55 | {' '} |
| 56 | ERROR{' '} |
| 57 | </Text> |
| 58 | |
| 59 | <Text> {error.message}</Text> |
| 60 | </Box> |
| 61 | |
| 62 | {origin && filePath && <Box marginTop={1}> |
| 63 | <Text dim> |
| 64 | {filePath}:{origin.line}:{origin.column} |
| 65 | </Text> |
| 66 | </Box>} |
| 67 | |
| 68 | {origin && excerpt && <Box marginTop={1} flexDirection="column"> |
| 69 | {excerpt.map(({ |
| 70 | line: line_0, |
| 71 | value |
| 72 | }) => <Box key={line_0}> |
| 73 | <Box width={lineWidth + 1}> |
| 74 | <Text dim={line_0 !== origin.line} backgroundColor={line_0 === origin.line ? 'ansi:red' : undefined} color={line_0 === origin.line ? 'ansi:white' : undefined}> |
| 75 | {String(line_0).padStart(lineWidth, ' ')}: |
| 76 | </Text> |
| 77 | </Box> |
| 78 | |
| 79 | <Text key={line_0} backgroundColor={line_0 === origin.line ? 'ansi:red' : undefined} color={line_0 === origin.line ? 'ansi:white' : undefined}> |
| 80 | {' ' + value} |
| 81 | </Text> |
| 82 | </Box>)} |
| 83 | </Box>} |
| 84 | |
| 85 | {error.stack && <Box marginTop={1} flexDirection="column"> |
nothing calls this directly
no test coverage detected