import React from "react"; import styled from "styled-components"; const Background = styled.div` background: repeating-linear-gradient( 45deg, transparent, transparent 20px, #f4d2ff 20px, #f4d2ff 21px ); margin: 10px 10px; padding: 10px 10px; border: 1px solid #f4d2ff; display: inline-block; position: relative; `; interface Props { width: number; height: number; name: string; } interface State { hasError: boolean; errorMessage: string; } class PanelErrorBoundary extends React.Component { constructor(props) { super(props); this.state = { hasError: false, errorMessage: ''}; } static getDerivedStateFromError(error): State { // Update state so the next render will show the fallback UI. return { hasError: true, errorMessage: error instanceof Error ? error.message : "Unknown error (thrown value was not an instance of Error)", }; } override componentDidCatch(error, info): void { // You can also log the error to an error reporting service console.error(error); console.error(info); } override render(): React.ReactNode { if (!this.state.hasError) return this.props.children; /** * We could add something like * * but it risks rendering an incorrect state so I'd prefer not to */ return (

{`Error! Something's gone wrong within the ${this.props.name} panel`}

{`Error message: "${this.state.errorMessage}"`}

{'Please consider making a bug report either on '} GitHub {' or via '} email. (The more information you can include the better - things such as steps to reproduce the bug, your browser version, the version of Auspice etc are incredibly helpful.)

In the meantime you could try refreshing the page which may fix things in the short term.

); } } export default PanelErrorBoundary;