2018-11-28 15:01:40 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-28 16:38:10 +02:00
|
|
|
import { PureComponent } from 'react';
|
|
|
|
|
2018-11-28 15:01:40 +01:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2023-05-28 16:38:10 +02:00
|
|
|
|
|
|
|
import { Helmet } from 'react-helmet';
|
|
|
|
|
|
|
|
import StackTrace from 'stacktrace-js';
|
|
|
|
|
2022-10-11 10:17:04 +02:00
|
|
|
import { source_url } from 'flavours/glitch/initial_state';
|
2022-10-11 10:41:15 +02:00
|
|
|
import { preferencesLink } from 'flavours/glitch/utils/backend_links';
|
2018-11-28 15:01:40 +01:00
|
|
|
|
2023-05-28 14:18:23 +02:00
|
|
|
export default class ErrorBoundary extends PureComponent {
|
2018-11-28 15:01:40 +01:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
children: PropTypes.node,
|
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
hasError: false,
|
2020-02-19 23:16:29 +01:00
|
|
|
errorMessage: undefined,
|
2018-11-28 15:01:40 +01:00
|
|
|
stackTrace: undefined,
|
2020-02-19 23:16:29 +01:00
|
|
|
mappedStackTrace: undefined,
|
2018-11-28 15:01:40 +01:00
|
|
|
componentStack: undefined,
|
2023-02-03 20:52:07 +01:00
|
|
|
};
|
2018-11-28 15:01:40 +01:00
|
|
|
|
|
|
|
componentDidCatch(error, info) {
|
|
|
|
this.setState({
|
|
|
|
hasError: true,
|
2020-02-19 23:16:29 +01:00
|
|
|
errorMessage: error.toString(),
|
2018-11-28 15:01:40 +01:00
|
|
|
stackTrace: error.stack,
|
|
|
|
componentStack: info && info.componentStack,
|
2020-02-19 23:16:29 +01:00
|
|
|
mappedStackTrace: undefined,
|
|
|
|
});
|
|
|
|
|
|
|
|
StackTrace.fromError(error).then((stackframes) => {
|
|
|
|
this.setState({
|
|
|
|
mappedStackTrace: stackframes.map((sf) => sf.toString()).join('\n'),
|
|
|
|
});
|
|
|
|
}).catch(() => {
|
|
|
|
this.setState({
|
|
|
|
mappedStackTrace: undefined,
|
|
|
|
});
|
2018-11-28 15:01:40 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handleReload(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2020-02-19 23:16:29 +01:00
|
|
|
const { hasError, errorMessage, stackTrace, mappedStackTrace, componentStack } = this.state;
|
2018-11-28 15:01:40 +01:00
|
|
|
|
|
|
|
if (!hasError) return this.props.children;
|
|
|
|
|
2020-09-14 15:05:22 +02:00
|
|
|
const likelyBrowserAddonIssue = errorMessage && errorMessage.includes('NotFoundError');
|
|
|
|
|
2018-11-28 15:01:40 +01:00
|
|
|
let debugInfo = '';
|
|
|
|
if (stackTrace) {
|
2020-02-19 23:16:29 +01:00
|
|
|
debugInfo += 'Stack trace\n-----------\n\n```\n' + errorMessage + '\n' + stackTrace.toString() + '\n```';
|
|
|
|
}
|
|
|
|
if (mappedStackTrace) {
|
|
|
|
debugInfo += 'Mapped stack trace\n-----------\n\n```\n' + errorMessage + '\n' + mappedStackTrace.toString() + '\n```';
|
2018-11-28 15:01:40 +01:00
|
|
|
}
|
|
|
|
if (componentStack) {
|
|
|
|
if (debugInfo) {
|
|
|
|
debugInfo += '\n\n\n';
|
|
|
|
}
|
|
|
|
debugInfo += 'React component stack\n---------------------\n\n```\n' + componentStack.toString() + '\n```';
|
|
|
|
}
|
|
|
|
|
2021-09-08 13:47:48 +02:00
|
|
|
let issueTracker = source_url;
|
|
|
|
if (source_url.match(/^https:\/\/github\.com\/[^/]+\/[^/]+\/?$/)) {
|
|
|
|
issueTracker = source_url + '/issues';
|
|
|
|
}
|
|
|
|
|
2018-11-28 15:01:40 +01:00
|
|
|
return (
|
2023-04-04 16:33:44 +02:00
|
|
|
<div tabIndex={-1}>
|
2018-11-28 15:01:40 +01:00
|
|
|
<div className='error-boundary'>
|
|
|
|
<h1><FormattedMessage id='web_app_crash.title' defaultMessage="We're sorry, but something went wrong with the Mastodon app." /></h1>
|
|
|
|
<p>
|
|
|
|
<FormattedMessage id='web_app_crash.content' defaultMessage='You could try any of the following:' />
|
2019-07-01 13:38:00 +02:00
|
|
|
</p>
|
|
|
|
<ul>
|
2020-09-14 15:05:22 +02:00
|
|
|
{ likelyBrowserAddonIssue && (
|
|
|
|
<li>
|
|
|
|
<FormattedMessage
|
|
|
|
id='web_app_crash.disable_addons'
|
|
|
|
defaultMessage='Disable browser add-ons or built-in translation tools'
|
|
|
|
/>
|
|
|
|
</li>
|
|
|
|
) }
|
2019-07-01 13:38:00 +02:00
|
|
|
<li>
|
|
|
|
<FormattedMessage
|
|
|
|
id='web_app_crash.report_issue'
|
|
|
|
defaultMessage='Report a bug in the {issuetracker}'
|
2021-09-08 13:47:48 +02:00
|
|
|
values={{ issuetracker: <a href={issueTracker} rel='noopener noreferrer' target='_blank'><FormattedMessage id='web_app_crash.issue_tracker' defaultMessage='issue tracker' /></a> }}
|
2019-07-01 13:38:00 +02:00
|
|
|
/>
|
|
|
|
{ debugInfo !== '' && (
|
|
|
|
<details>
|
|
|
|
<summary><FormattedMessage id='web_app_crash.debug_info' defaultMessage='Debug information' /></summary>
|
|
|
|
<textarea
|
|
|
|
className='web_app_crash-stacktrace'
|
|
|
|
value={debugInfo}
|
|
|
|
rows='10'
|
|
|
|
readOnly
|
|
|
|
/>
|
|
|
|
</details>
|
|
|
|
)}
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<FormattedMessage
|
|
|
|
id='web_app_crash.reload_page'
|
|
|
|
defaultMessage='{reload} the current page'
|
|
|
|
values={{ reload: <a href='#' onClick={this.handleReload}><FormattedMessage id='web_app_crash.reload' defaultMessage='Reload' /></a> }}
|
|
|
|
/>
|
|
|
|
</li>
|
|
|
|
{ preferencesLink !== undefined && (
|
2018-11-28 15:01:40 +01:00
|
|
|
<li>
|
|
|
|
<FormattedMessage
|
2019-07-01 13:38:00 +02:00
|
|
|
id='web_app_crash.change_your_settings'
|
|
|
|
defaultMessage='Change your {settings}'
|
|
|
|
values={{ settings: <a href={preferencesLink}><FormattedMessage id='web_app_crash.settings' defaultMessage='settings' /></a> }}
|
2018-11-28 15:01:40 +01:00
|
|
|
/>
|
|
|
|
</li>
|
2019-07-01 13:38:00 +02:00
|
|
|
)}
|
|
|
|
</ul>
|
2018-11-28 15:01:40 +01:00
|
|
|
</div>
|
2022-10-20 14:35:29 +02:00
|
|
|
|
|
|
|
<Helmet>
|
|
|
|
<meta name='robots' content='noindex' />
|
|
|
|
</Helmet>
|
2018-11-28 15:01:40 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|