1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/ElectronClient/gui/ErrorBoundary.tsx
Laurent Cozic c63c6370b5 Desktop: Refactored command system
The goal is to make the command system more modular, so each command can
be defined as a single object that includes a declaration (name, label,
etc.) and a runtime (to execute the command, test if it should be
enabled, etc.)

Utility methods are provided to convert a command to a menu item or a
toolbar button, thus reducing duplicated and boiler plate code across the
codebase (often the menu item logic was duplicated in the toolbar
button logic and vice versa).

The goal is to make it easier to add new commands (and associated menu
item and toolbar buttons) and to call them from
anywhere. This is also useful for plugins, which can also easily define
new commands.

Could also allow creating a command palette.
2020-07-03 22:32:39 +01:00

49 lines
1.2 KiB
TypeScript

import * as React from 'react';
export default class ErrorBoundary extends React.Component {
state:any = { error: null, errorInfo: null };
componentDidCatch(error:any, errorInfo:any) {
this.setState({ error: error, errorInfo: errorInfo });
}
render() {
if (this.state.error) {
try {
const output = [];
output.push(<h2>Message</h2>);
output.push(<p>{this.state.error.message}</p>);
if (this.state.error.stack) {
output.push(<h2>Stack trace</h2>);
output.push(<pre>{this.state.error.stack}</pre>);
}
if (this.state.errorInfo) {
if (this.state.errorInfo.componentStack) {
output.push(<h2>Component stack</h2>);
output.push(<pre>{this.state.errorInfo.componentStack}</pre>);
}
}
return (
<div style={{ overflow: 'auto', fontFamily: 'sans-serif', padding: '5px 20px' }}>
<h1>Error</h1>
<p>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.</p>
{output}
</div>
);
} catch (error) {
return (
<div>
{JSON.stringify(this.state)}
</div>
);
}
}
return this.props.children;
}
}