Skip to content

Commit fb3871d

Browse files
committed
Refactor InternalError with modular suggestions
1 parent 0b56e6f commit fb3871d

File tree

6 files changed

+50
-27
lines changed

6 files changed

+50
-27
lines changed

frontend/src/Feedback.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {uuidv4} from "sync-message";
88
import Popup from "reactjs-popup";
99
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
1010
import {faBug} from "@fortawesome/free-solid-svg-icons";
11+
import _ from "lodash";
1112

1213
const SENTRY_DSN = process.env.REACT_APP_SENTRY_DSN;
1314

@@ -134,3 +135,23 @@ export function FeedbackMenuButton() {
134135
</Popup>
135136
</p>;
136137
}
138+
139+
export function InternalError({ranCode}) {
140+
const start = _.template(terms.internal_error_start)({
141+
maybeErrorReported: SENTRY_DSN ? terms.error_has_been_reported : '',
142+
});
143+
const suggestions = [];
144+
if (ranCode) {
145+
suggestions.push(terms.try_running_code_again);
146+
}
147+
suggestions.push(terms.refresh_and_try_again, terms.try_using_different_browser);
148+
if (SENTRY_DSN) {
149+
suggestions.push(terms.give_feedback_from_menu);
150+
}
151+
return <div>
152+
<p>{start}</p>
153+
<ul>
154+
{suggestions.map(suggestion => <li key={suggestion}>{suggestion}</li>)}
155+
</ul>
156+
</div>;
157+
}

frontend/src/RunCode.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import {
33
bookState,
44
currentStep,
55
currentStepName,
6-
postCodeEntry,
76
loadedPromise,
87
logEvent,
98
moveStep,
9+
postCodeEntry,
1010
ranCode
1111
} from "./book/store";
1212
import _ from "lodash";
@@ -15,8 +15,7 @@ import {animateScroll} from "react-scroll";
1515
import React from "react";
1616
import * as Sentry from "@sentry/react";
1717
import {wrapAsync} from "./frontendlib/sentry";
18-
import {taskClient, runCodeTask} from "./TaskClient";
19-
import * as terms from "./terms.json";
18+
import {runCodeTask, taskClient} from "./TaskClient";
2019

2120
export const terminalRef = React.createRef();
2221

@@ -215,12 +214,9 @@ export const showCodeResult = ({birdseyeUrl, passed}) => {
215214
}
216215

217216
function showInternalErrorOutput(message) {
218-
let instructions = process.env.REACT_APP_SENTRY_DSN ?
219-
terms.report_error_instructions :
220-
terms.report_error_instructions_no_feedback;
221217
showOutputParts([
222218
{text: `\n${message.trim()}\n\n`, type: 'internal_error'},
223-
{text: instructions, type: 'internal_error_explanation'},
219+
{text: '', type: 'internal_error_explanation'},
224220
{text: '>>> ', type: 'shell_prompt'},
225221
]);
226222
}

frontend/src/english_terms.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818
"error_traceback":"Error traceback:",
1919
"did_you_mean": "Did you mean...",
2020
"similar_frames_skipped": "Similar frames skipped:",
21-
"report_error_instructions": "Oops, something went wrong! The error has been reported. Here's what you can do:\n\n- Try running the code again.\n- Reload/refresh the page and try again.\n- Try using a different browser.\n- Give feedback from the top-left menu.",
22-
"report_error_instructions_no_feedback": "Oops, something went wrong! Here's what you can do:\n\n- Try running the code again.\n- Reload/refresh the page and try again.\n- Try using a different browser.",
21+
"internal_error_start": "Oops, something went wrong! ${maybeErrorReported} Here's what you can do:",
22+
"error_has_been_reported": "The error has been reported.",
23+
"try_running_code_again": "Try running the code again.",
24+
"refresh_and_try_again": "Reload/refresh the page and try again.",
25+
"try_using_different_browser": "Try using a different browser.",
26+
"give_feedback_from_menu": "Give feedback from the top-left menu.",
2327
"click_for_error_details": "Click for error details",
2428
"give_feedback": "Give feedback",
2529
"feedback_email_placeholder": "Email (optional)",

frontend/src/shell/TerminalMessage.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import AnsiUp from "ansi_up";
44
import sourceStyles from './defs/styles/TerminalMessage'
55
import * as terms from "../terms.json"
66
import _ from "lodash";
7+
import {InternalError} from "../Feedback";
78

89
const ansi_up = new AnsiUp();
910

@@ -27,7 +28,7 @@ export default class TerminalMessage extends Component {
2728
}
2829

2930
if (content.type === "internal_error_explanation") {
30-
return <div dangerouslySetInnerHTML={{__html: content.text}}/>
31+
return <InternalError ranCode/>
3132
}
3233

3334
let color = "white";

translations/english.po

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19689,6 +19689,9 @@ msgstr "Enables the \"Reverse step\" and \"Skip step\" buttons."
1968919689
msgid "frontend.did_you_mean"
1969019690
msgstr "Did you mean..."
1969119691

19692+
msgid "frontend.error_has_been_reported"
19693+
msgstr "The error has been reported."
19694+
1969219695
msgid "frontend.error_traceback"
1969319696
msgstr "Error traceback:"
1969419697

@@ -19730,6 +19733,9 @@ msgstr "Get a hint"
1973019733
msgid "frontend.give_feedback"
1973119734
msgstr "Give feedback"
1973219735

19736+
msgid "frontend.give_feedback_from_menu"
19737+
msgstr "Give feedback from the top-left menu."
19738+
1973319739
msgid "frontend.give_feedback_instructions"
1973419740
msgstr ""
1973519741
"Tell us what you like or don't like! If you're reporting a bug, give a detailed description of the problem:\n"
@@ -19750,6 +19756,9 @@ msgstr "Hints and Solution"
1975019756
msgid "frontend.hints_progress"
1975119757
msgstr "Shown ${numHints} of ${totalHints} hints"
1975219758

19759+
msgid "frontend.internal_error_start"
19760+
msgstr "Oops, something went wrong! ${maybeErrorReported} Here's what you can do:"
19761+
1975319762
msgid "frontend.loading_wait"
1975419763
msgstr "Loading..."
1975519764

@@ -19831,26 +19840,12 @@ msgstr ""
1983119840
"\n"
1983219841
"If your question is about servers (e.g. Django or Flask), web requests, databases, or a package that can't be imported here, then this tool won't work. However, just because your current code *involves* those things, that doesn't mean that's what your question is *about*. If you're having a general Python/programming/logic problem, then extract that problem from the other stuff. Python with Django is still Python. If you can't do that, then read [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) before asking your question."
1983319842

19843+
msgid "frontend.refresh_and_try_again"
19844+
msgstr "Reload/refresh the page and try again."
19845+
1983419846
msgid "frontend.repeated_frames_description"
1983519847
msgstr "${name} at line ${lineno} (${count} times)"
1983619848

19837-
msgid "frontend.report_error_instructions"
19838-
msgstr ""
19839-
"Oops, something went wrong! The error has been reported. Here's what you can do:\n"
19840-
"\n"
19841-
"- Try running the code again.\n"
19842-
"- Reload/refresh the page and try again.\n"
19843-
"- Try using a different browser.\n"
19844-
"- Give feedback from the top-left menu."
19845-
19846-
msgid "frontend.report_error_instructions_no_feedback"
19847-
msgstr ""
19848-
"Oops, something went wrong! Here's what you can do:\n"
19849-
"\n"
19850-
"- Try running the code again.\n"
19851-
"- Reload/refresh the page and try again.\n"
19852-
"- Try using a different browser."
19853-
1985419849
msgid "frontend.requirements"
1985519850
msgstr "Requirements"
1985619851

@@ -19910,6 +19905,12 @@ msgstr ""
1991019905
"\n"
1991119906
"If you're completely new to programming, or you have doubts, just start at the beginning and click Next as you finish each page."
1991219907

19908+
msgid "frontend.try_running_code_again"
19909+
msgstr "Try running the code again."
19910+
19911+
msgid "frontend.try_using_different_browser"
19912+
msgstr "Try using a different browser."
19913+
1991319914
msgid "frontend.verbatim"
1991419915
msgstr ""
1991519916
"This step has only one correct answer. You must run exactly the correct code, so check your spelling carefully. Only a"
34 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)