Skip to content

Commit

Permalink
Merge pull request klembot#1132 from klembot/improve-global-error-bou…
Browse files Browse the repository at this point in the history
…ndary

Improve global error boundary
  • Loading branch information
klembot authored Apr 30, 2022
2 parents a62edbb + 48f68cf commit a41801e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('<GlobalErrorBoundary>', () => {
</GlobalErrorBoundary>
);
expect(
screen.getByText('An error occurred', {exact: false})
screen.getByText('An unrecoverable error has occurred', {exact: false})
).toBeInTheDocument();
});
});
28 changes: 28 additions & 0 deletions src/components/global-error-boundary/global-error-boundary.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.global-error-boundary {
align-items: center;
justify-content: center;
display: grid;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: black;
color: white;
}

.global-error-boundary .fuuu {
font-size: 200%;
margin-bottom: 0;
}

.global-error-boundary a {
color: blue;
}

.global-error-boundary pre {
border: 1px solid white;
max-height: 20em;
overflow: scroll;
padding: 10px;
}
30 changes: 27 additions & 3 deletions src/components/global-error-boundary/global-error-boundary.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from 'react';

// TODO make this user-friendly
import './global-error-boundary.css';

export interface GlobalErrorBoundaryState {
error: Error | null;
Expand All @@ -22,8 +21,33 @@ export class GlobalErrorBoundary extends React.Component<
}

public render() {
// Non-localized because our localization might be broken.

if (this.state.error) {
return <p>An error occurred: {this.state.error.message}</p>;
return (
<div className="global-error-boundary">
<div>
<p className="fuuu" aria-hidden>
💔
</p>
<p>An unrecoverable error has occurred.</p>
<p>Please try restarting Twine or reloading the page.</p>
<p>
If you see this message repeatedly, please{' '}
<a
href="https://twinery.org/2bugs"
rel="noreferrer"
target="_blank"
>
report a bug
</a>
.
</p>
<p>Details:</p>
<pre>{this.state.error.stack}</pre>
</div>
</div>
);
}

return this.props.children;
Expand Down

0 comments on commit a41801e

Please sign in to comment.