import * as React from 'react'; import versionInfo from 'lib/versionInfo'; const packageInfo = require('../packageInfo.js'); const ipcRenderer = require('electron').ipcRenderer; export default class ErrorBoundary extends React.Component { state:any = { error: null, errorInfo: null }; componentDidCatch(error:any, errorInfo:any) { this.setState({ error: error, errorInfo: errorInfo }); } componentDidMount() { const onAppClose = () => { ipcRenderer.send('asynchronous-message', 'appCloseReply', { canClose: true, }); }; ipcRenderer.on('appClose', onAppClose); } render() { if (this.state.error) { try { const output = []; output.push(

Message

{this.state.error.message}

); output.push(

Version info

{versionInfo(packageInfo).message}
); if (this.state.error.stack) { output.push(

Stack trace

{this.state.error.stack}
); } if (this.state.errorInfo) { if (this.state.errorInfo.componentStack) { output.push(

Component stack

{this.state.errorInfo.componentStack}
); } } return (

Error

Joplin encountered a fatal error and could not continue. To report the error, please copy the *entire content* of this page and post it on Joplin forum or GitHub.

{output}
); } catch (error) { return (
{JSON.stringify(this.state)}
); } } return this.props.children; } }