import * as React from "react"; import StackTrace from "stacktrace-js"; import {CircularProgress} from "@mui/material"; import Button from "@mui/material/Button"; class ErrorBoundary extends React.Component { constructor(props) { super(props); this.state = { error: false, originalStack: null, niceStack: null }; } componentDidCatch(error, info) { console.error("[ErrorBoundary] Error caught", error, info); // Immediately render original stack trace const prettierOriginalStack = info.componentStack .trim() .split("\n") .map(line => ` at ${line}`) .join("\n"); this.setState({ error: true, originalStack: `${error.toString()}\n${prettierOriginalStack}` }); // Fetch additional info and a better stack trace StackTrace.fromError(error).then(stack => { console.error("[ErrorBoundary] Stacktrace fetched", stack); const niceStack = `${error.toString()}\n` + stack.map( el => ` at ${el.functionName} (${el.fileName}:${el.columnNumber}:${el.lineNumber})`).join("\n"); this.setState({ niceStack }); }); } copyStack() { let stack = ""; if (this.state.niceStack) { stack += `${this.state.niceStack}\n\n`; } stack += `${this.state.originalStack}\n`; navigator.clipboard.writeText(stack); } render() { if (this.state.error) { return (

Oh no, ntfy crashed 😮

This should obviously not happen. Very sorry about this.
If you have a minute, please report this on GitHub, or let us know via Discord or Matrix.

Stack trace

{this.state.niceStack ?
{this.state.niceStack}
: <> Gather more info ...}
{this.state.originalStack}
); } return this.props.children; } } export default ErrorBoundary;