Skip to content

Commit ab6205d

Browse files
committed
ErrorBoundary
1 parent fb3871d commit ab6205d

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

frontend/src/App.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import {
4747
import {HintsAssistant} from "./Hints";
4848
import Toggle from 'react-toggle'
4949
import "react-toggle/style.css"
50-
import {FeedbackMenuButton} from "./Feedback";
50+
import {ErrorBoundary, FeedbackMenuButton} from "./Feedback";
5151
import birdseyeIcon from "./img/birdseye_icon.png";
5252
import languageIcon from "./img/language.png";
5353
import {interrupt, runCode, terminalRef} from "./RunCode";
@@ -433,7 +433,9 @@ class AppComponent extends React.Component {
433433

434434
return <div className="book-container">
435435
<NavBar user={this.props.user}/>
436-
<AppMain {...this.props}/>
436+
<ErrorBoundary canGiveFeedback>
437+
<AppMain {...this.props}/>
438+
</ErrorBoundary>
437439
</div>
438440
}
439441
}

frontend/src/Feedback.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export function FeedbackMenuButton() {
136136
</p>;
137137
}
138138

139-
export function InternalError({ranCode}) {
139+
export function InternalError({ranCode, canGiveFeedback}) {
140140
const start = _.template(terms.internal_error_start)({
141141
maybeErrorReported: SENTRY_DSN ? terms.error_has_been_reported : '',
142142
});
@@ -145,7 +145,7 @@ export function InternalError({ranCode}) {
145145
suggestions.push(terms.try_running_code_again);
146146
}
147147
suggestions.push(terms.refresh_and_try_again, terms.try_using_different_browser);
148-
if (SENTRY_DSN) {
148+
if (SENTRY_DSN && canGiveFeedback) {
149149
suggestions.push(terms.give_feedback_from_menu);
150150
}
151151
return <div>
@@ -155,3 +155,20 @@ export function InternalError({ranCode}) {
155155
</ul>
156156
</div>;
157157
}
158+
159+
export function ErrorBoundary({children, canGiveFeedback}) {
160+
return <Sentry.ErrorBoundary fallback={
161+
({error}) => <ErrorFallback {...{error, canGiveFeedback}}/>
162+
}>
163+
{children}
164+
</Sentry.ErrorBoundary>;
165+
}
166+
167+
function ErrorFallback({error, canGiveFeedback}) {
168+
return <div style={{margin: "4em"}}>
169+
<div className="alert alert-danger" role="alert">
170+
<pre><code>{error.toString()}</code></pre>
171+
</div>
172+
<InternalError canGiveFeedback={canGiveFeedback}/>
173+
</div>;
174+
}

frontend/src/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ import ReactDOM from 'react-dom';
33
import {App} from './App';
44
import {Provider} from "react-redux";
55
import {store} from "./store";
6+
import {ErrorBoundary} from "./Feedback";
67

78

89
import * as serviceWorkerRegistration from './serviceWorkerRegistration';
910

1011

1112
ReactDOM.render(
12-
<Provider store={store}>
13+
<Provider store={store}>
14+
<ErrorBoundary>
1315
<App/>
14-
</Provider>,
16+
</ErrorBoundary>
17+
</Provider>,
1518
document.getElementById("root")
1619
);
1720

frontend/src/shell/TerminalMessage.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default class TerminalMessage extends Component {
2828
}
2929

3030
if (content.type === "internal_error_explanation") {
31-
return <InternalError ranCode/>
31+
return <InternalError ranCode canGiveFeedback/>
3232
}
3333

3434
let color = "white";

0 commit comments

Comments
 (0)