import { Component, ErrorInfo, ReactNode } from 'react'; import { AlertTriangle } from 'lucide-react'; interface Props { children: ReactNode; fallback?: ReactNode; onError?: (error: Error, errorInfo: ErrorInfo) => void; } interface State { hasError: boolean; error: Error | null; } /** * ErrorBoundary component to catch and handle React errors gracefully. * * Primarily used to catch JSONB parsing errors in pattern detection components * without crashing the entire InfoCenter UI. * * @example * ```tsx * Unable to display pattern data} * onError={(error) => console.error('Pattern error:', error)} * > * * * ``` */ export class ErrorBoundary extends Component { constructor(props: Props) { super(props); this.state = { hasError: false, error: null }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error('ErrorBoundary caught error:', error, errorInfo); this.props.onError?.(error, errorInfo); } render() { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback; } return (

Something went wrong

Unable to display this content due to a data parsing error.

Error details
              {this.state.error?.message}
            
); } return this.props.children; } }