import React from 'react'; interface ErrorViewerProps { errorInfo: { error_class?: string; error_message?: string; traceback?: string; llm_provider?: string; error_code?: string | number; }; } export const ErrorViewer: React.FC = ({ errorInfo }) => { const [expandedFrames, setExpandedFrames] = React.useState<{[key: number]: boolean}>({}); const [allExpanded, setAllExpanded] = React.useState(false); // Toggle individual frame const toggleFrame = (index: number) => { setExpandedFrames(prev => ({ ...prev, [index]: !prev[index] })); }; // Toggle all frames const toggleAllFrames = () => { const newState = !allExpanded; setAllExpanded(newState); if (tracebackFrames.length > 0) { const newExpandedState: {[key: number]: boolean} = {}; tracebackFrames.forEach((_, idx) => { newExpandedState[idx] = newState; }); setExpandedFrames(newExpandedState); } }; // Parse traceback into frames const parseTraceback = (traceback: string) => { if (!traceback) return []; // Extract file paths, line numbers and code from traceback const fileLineRegex = /File "([^"]+)", line (\d+)/g; const matches = Array.from(traceback.matchAll(fileLineRegex)); // Create simplified frames return matches.map(match => { const filePath = match[1]; const lineNumber = match[2]; const fileName = filePath.split('/').pop() || filePath; // Extract the context around this frame const matchIndex = match.index || 0; const nextMatchIndex = traceback.indexOf('File "', matchIndex + 1); const frameContent = nextMatchIndex > -1 ? traceback.substring(matchIndex, nextMatchIndex).trim() : traceback.substring(matchIndex).trim(); // Try to extract the code line const lines = frameContent.split('\n'); let code = ''; if (lines.length > 1) { code = lines[lines.length - 1].trim(); } return { filePath, fileName, lineNumber, code, inFunction: frameContent.includes(' in ') ? frameContent.split(' in ')[1].split('\n')[0] : '' }; }); }; const tracebackFrames = errorInfo.traceback ? parseTraceback(errorInfo.traceback) : []; return (

Error Details

Type: {errorInfo.error_class || "Unknown Error"}
Message: {errorInfo.error_message || "Unknown error occurred"}
{errorInfo.traceback && (

Traceback

{tracebackFrames.map((frame, index) => (
toggleFrame(index)} >
{frame.lineNumber} {frame.fileName} in {frame.inFunction || frame.fileName}
{(expandedFrames[index] || false) && frame.code && (
{frame.code}
)}
))}
)}
); };