Add source-mapped stacktrace to error message in web UI (#13082)
* Add source-mapped stack trace to copyable text in error boundary * Add the error message to the copied report, not only the stack trace
This commit is contained in:
parent
d8e9bae482
commit
ff3a11d01d
3 changed files with 64 additions and 3 deletions
|
@ -2,6 +2,7 @@ import React from 'react';
|
|||
import PropTypes from 'prop-types';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import { version, source_url } from 'mastodon/initial_state';
|
||||
import StackTrace from 'stacktrace-js';
|
||||
|
||||
export default class ErrorBoundary extends React.PureComponent {
|
||||
|
||||
|
@ -11,24 +12,42 @@ export default class ErrorBoundary extends React.PureComponent {
|
|||
|
||||
state = {
|
||||
hasError: false,
|
||||
errorMessage: undefined,
|
||||
stackTrace: undefined,
|
||||
mappedStackTrace: undefined,
|
||||
componentStack: undefined,
|
||||
};
|
||||
|
||||
componentDidCatch (error, info) {
|
||||
this.setState({
|
||||
hasError: true,
|
||||
errorMessage: error.toString(),
|
||||
stackTrace: error.stack,
|
||||
componentStack: info && info.componentStack,
|
||||
copied: false,
|
||||
mappedStackTrace: undefined,
|
||||
});
|
||||
|
||||
StackTrace.fromError(error).then((stackframes) => {
|
||||
this.setState({
|
||||
mappedStackTrace: stackframes.map((sf) => sf.toString()).join('\n'),
|
||||
});
|
||||
}).catch(() => {
|
||||
this.setState({
|
||||
mappedStackTrace: undefined,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
handleCopyStackTrace = () => {
|
||||
const { stackTrace } = this.state;
|
||||
const { errorMessage, stackTrace, mappedStackTrace } = this.state;
|
||||
const textarea = document.createElement('textarea');
|
||||
|
||||
textarea.textContent = stackTrace;
|
||||
let contents = [errorMessage, stackTrace];
|
||||
if (mappedStackTrace) {
|
||||
contents.push(mappedStackTrace);
|
||||
}
|
||||
|
||||
textarea.textContent = contents.join('\n\n\n');
|
||||
textarea.style.position = 'fixed';
|
||||
|
||||
document.body.appendChild(textarea);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue