diff --git a/app/javascript/flavours/glitch/components/error_boundary.jsx b/app/javascript/flavours/glitch/components/error_boundary.jsx index 4a4dadf0a5..248b866475 100644 --- a/app/javascript/flavours/glitch/components/error_boundary.jsx +++ b/app/javascript/flavours/glitch/components/error_boundary.jsx @@ -7,8 +7,7 @@ import { Helmet } from 'react-helmet'; import StackTrace from 'stacktrace-js'; -import { source_url } from 'flavours/glitch/initial_state'; -import { preferencesLink } from 'flavours/glitch/utils/backend_links'; +import { version, source_url } from 'flavours/glitch/initial_state'; export default class ErrorBoundary extends PureComponent { @@ -24,7 +23,7 @@ export default class ErrorBoundary extends PureComponent { componentStack: undefined, }; - componentDidCatch(error, info) { + componentDidCatch (error, info) { this.setState({ hasError: true, errorMessage: error.toString(), @@ -44,88 +43,62 @@ export default class ErrorBoundary extends PureComponent { }); } - handleReload(e) { - e.preventDefault(); - window.location.reload(); - } + handleCopyStackTrace = () => { + const { errorMessage, stackTrace, mappedStackTrace } = this.state; + const textarea = document.createElement('textarea'); + + let contents = [errorMessage, stackTrace]; + if (mappedStackTrace) { + contents.push(mappedStackTrace); + } + + textarea.textContent = contents.join('\n\n\n'); + textarea.style.position = 'fixed'; + + document.body.appendChild(textarea); + + try { + textarea.select(); + document.execCommand('copy'); + } catch (e) { + + } finally { + document.body.removeChild(textarea); + } + + this.setState({ copied: true }); + setTimeout(() => this.setState({ copied: false }), 700); + }; render() { - const { hasError, errorMessage, stackTrace, mappedStackTrace, componentStack } = this.state; + const { hasError, copied, errorMessage } = this.state; - if (!hasError) return this.props.children; + if (!hasError) { + return this.props.children; + } const likelyBrowserAddonIssue = errorMessage && errorMessage.includes('NotFoundError'); - let debugInfo = ''; - if (stackTrace) { - 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```'; - } - if (componentStack) { - if (debugInfo) { - debugInfo += '\n\n\n'; - } - debugInfo += 'React component stack\n---------------------\n\n```\n' + componentStack.toString() + '\n```'; - } - - let issueTracker = source_url; - if (source_url.match(/^https:\/\/github\.com\/[^/]+\/[^/]+\/?$/)) { - issueTracker = source_url + '/issues'; - } - return ( -
-
-

-

- -

-