import { Alert, Accordion, Stack, Text, Box } from '@chakra-ui/react'; import { Fragment } from 'react'; import { ErrorLike } from '../../core/Atomic'; import { ChakraCodeBlock } from './CodeBlock'; import { ChakraClip } from './ChakraClipboard'; export interface ErrorAlertProps { error: ErrorLike status?: "error" | "info" | "warning" | "success" | "neutral" } export const ErrorAlert = (props: ErrorAlertProps) => { let causes: ErrorData[] = []; if(props.error.cause !== undefined && typeof props.error.cause === 'object') { causes = walkError(props.error.cause as ErrorLike); } return ( {props.error.name ?? 'Error'} {props.error.message} {props.error.stack !== undefined ? : null} {causes.map(x => ( Caused By: {x.name ?? ''}{x.code !== undefined ? ` (${x.code}) ` : ''}{x.message} {x.stack !== undefined ? : null} ))} ) } interface ErrorData { name?: string code?: string message?: string stack?: string } const walkError = (err: ErrorLike, errors: ErrorData[] = []): ErrorData[] => { const thisErr: ErrorData = { name: err.name, code: 'code' in err ? err.code : undefined, message: err.message, stack: err.stack }; errors.push(thisErr); if(err.cause !== undefined && typeof err.cause === 'object') { return walkError(err, errors); } return errors; }