/
ShamilS
/
claude-code
Обзор
Документация
Войти
/
ShamilS
/
claude-code
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ink/components/ErrorOverview.tsx
109 строк
15 KB
kuberwastaken
new initial commit (history rewritten)
01 апр 2026, 14:57
01 апр 2026, 14:57
c1996f2
Код
Авторство
О чём код?
import codeExcerpt, { type CodeExcerpt } from 'code-excerpt'; import { readFileSync } from 'fs'; import React from 'react'; import StackUtils from 'stack-utils'; import Box from './Box.js'; import Text from './Text.js'; /* eslint-disable custom-rules/no-process-cwd -- stack trace file:// paths are relative to the real OS cwd, not the virtual cwd */ // Error's source file is reported as file:///home/user/file.js // This function removes the file://[cwd] part const cleanupPath = (path: string | undefined): string | undefined => { return path?.replace(`file://${process.cwd()}/`, ''); }; let stackUtils: StackUtils | undefined; function getStackUtils(): StackUtils { return stackUtils ??= new StackUtils({ cwd: process.cwd(), internals: StackUtils.nodeInternals() }); } /* eslint-enable custom-rules/no-process-cwd */ type Props = { readonly error: Error; }; export default function ErrorOverview({ error }: Props) { const stack = error.stack ? error.stack.split('\n').slice(1) : undefined; const origin = stack ? getStackUtils().parseLine(stack[0]!) : undefined; const filePath = cleanupPath(origin?.file); let excerpt: CodeExcerpt[] | undefined; let lineWidth = 0; if (filePath && origin?.line) { try { // eslint-disable-next-line custom-rules/no-sync-fs -- sync render path; error overlay can't go async without suspense restructuring const sourceCode = readFileSync(filePath, 'utf8'); excerpt = codeExcerpt(sourceCode, origin.line); if (excerpt) { for (const { line } of excerpt) { lineWidth = Math.max(lineWidth, String(line).length); } } } catch { // file not readable — skip source context } } return <Box flexDirection="column" padding={1}> <Box> <Text backgroundColor="ansi:red" color="ansi:white"> {' '} ERROR{' '} </Text> <Text> {error.message}</Text> </Box> {origin && filePath && <Box marginTop={1}> <Text dim> {filePath}:{origin.line}:{origin.column} </Text> </Box>} {origin && excerpt && <Box marginTop={1} flexDirection="column"> {excerpt.map(({ line: line_0, value }) => <Box key={line_0}> <Box width={lineWidth + 1}> <Text dim={line_0 !== origin.line} backgroundColor={line_0 === origin.line ? 'ansi:red' : undefined} color={line_0 === origin.line ? 'ansi:white' : undefined}> {String(line_0).padStart(lineWidth, ' ')}: </Text> </Box> <Text key={line_0} backgroundColor={line_0 === origin.line ? 'ansi:red' : undefined} color={line_0 === origin.line ? 'ansi:white' : undefined}> {' ' + value} </Text> </Box>)} </Box>} {error.stack && <Box marginTop={1} flexDirection="column"> {error.stack.split('\n').slice(1).map(line_1 => { const parsedLine = getStackUtils().parseLine(line_1); // If the line from the stack cannot be parsed, we print out the unparsed line. if (!parsedLine) { return <Box key={line_1}> <Text dim>- </Text> <Text bold>{line_1}</Text> </Box>; } return <Box key={line_1}> <Text dim>- </Text> <Text bold>{parsedLine.function}</Text> <Text dim> {' '} ({cleanupPath(parsedLine.file) ?? ''}:{parsedLine.line}: {parsedLine.column}) </Text> </Box>; })} </Box>} </Box>; } //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJjb2RlRXhjZXJwdCIsIkNvZGVFeGNlcnB0IiwicmVhZEZpbGVTeW5jIiwiUmVhY3QiLCJTdGFja1V0aWxzIiwiQm94IiwiVGV4dCIsImNs … [Строка слишком длинная. Вы можете скачать файл]