Skip to content

Commit 6f236cc

Browse files
authored
Revert error location changes, keep errors including pfem in output (#1499)
This is to revert some of the changes merged in with this PR:#1487 ### Changes - Moved `ErrorMessage` back into output panel - Reverted `MobileProject` tab behaviour - Reverted associated tests - Removed pfem from web-component html
1 parent ed1216c commit 6f236cc

10 files changed

Lines changed: 61 additions & 95 deletions

File tree

src/assets/stylesheets/ErrorMessage.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
padding: var(--space-1);
99
overflow-y: auto;
1010
scrollbar-width: thin;
11-
max-block-size: 30%;
1211

1312
&__error {
1413
padding: 0;

src/components/Editor/EditorInput/EditorInput.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import EditorPanel from "../EditorPanel/EditorPanel";
1515
import DraggableTab from "../DraggableTabs/DraggableTab";
1616
import DroppableTabList from "../DraggableTabs/DroppableTabList";
1717
import RunBar from "../../RunButton/RunBar";
18-
import ErrorMessage from "../ErrorMessage/ErrorMessage";
1918

2019
import "../../../assets/stylesheets/EditorInput.scss";
2120
import RunnerControls from "../../RunButton/RunnerControls";
@@ -187,7 +186,6 @@ const EditorInput = () => {
187186
/>
188187
</TabPanel>
189188
))}
190-
<ErrorMessage />
191189
{isMobile ? null : <RunBar />}
192190
</Tabs>
193191
))}

src/components/Editor/EditorInput/EditorInput.test.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,3 @@ describe("When read only", () => {
188188
expect(screen.queryByText("editorPanel.viewOnly")).toBeInTheDocument();
189189
});
190190
});
191-
192-
describe("When there is an error", () => {
193-
beforeEach(() => {
194-
renderEditorInput({
195-
editor: { ...initialState.editor, error: "An error occurred" },
196-
});
197-
});
198-
199-
test("The error message is displayed", () => {
200-
expect(screen.getByText("An error occurred")).toBeInTheDocument();
201-
});
202-
});

src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ const PyodideRunner = ({
6161
const userId = user?.profile?.user;
6262
const isSplitView = useSelector((s) => s.editor.isSplitView);
6363
const isEmbedded = useSelector((s) => s.editor.isEmbedded);
64-
const isOutputOnly = useSelector((s) => s.editor.isOutputOnly);
6564
const reactAppApiEndpoint = useSelector((s) => s.editor.reactAppApiEndpoint);
6665
const codeRunTriggered = useSelector((s) => s.editor.codeRunTriggered);
6766
const codeRunStopped = useSelector((s) => s.editor.codeRunStopped);
@@ -472,7 +471,7 @@ const PyodideRunner = ({
472471
<RunnerControls skinny />
473472
)}
474473
</div>
475-
{isOutputOnly && <ErrorMessage />}
474+
<ErrorMessage />
476475
<TabPanel key={0}>
477476
<pre
478477
className={`pythonrunner-console pythonrunner-console--${settings.fontSize}`}
@@ -504,7 +503,7 @@ const PyodideRunner = ({
504503
{!isEmbedded && hasVisual && <OutputViewToggle />}
505504
{!isEmbedded && isMobile && <RunnerControls skinny />}
506505
</div>
507-
{isOutputOnly && <ErrorMessage />}
506+
<ErrorMessage />
508507
{hasVisual && (
509508
<TabPanel key={0}>
510509
<VisualOutputPane visuals={visuals} setVisuals={setVisuals} />

src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.test.js

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
openFile,
2222
setFocussedFileIndex,
2323
setFriendlyError,
24-
setIsOutputOnly,
2524
} from "../../../../../redux/EditorSlice.js";
2625
import store from "../../../../../app/store";
2726

@@ -440,31 +439,6 @@ describe("When an error is received", () => {
440439
});
441440
});
442441

443-
describe("When output-only is enabled", () => {
444-
beforeEach(() => {
445-
act(() => {
446-
store.dispatch(setIsOutputOnly(true));
447-
});
448-
449-
const worker = PyodideWorker.getLastInstance();
450-
worker.postMessageFromWorker({
451-
method: "handleError",
452-
line: 2,
453-
file: "main.py",
454-
type: "SyntaxError",
455-
info: "something's wrong",
456-
});
457-
});
458-
459-
test("it displays the error message", () => {
460-
expect(
461-
screen.queryByText(
462-
"SyntaxError: something's wrong on line 2 of main.py",
463-
),
464-
).toBeInTheDocument();
465-
});
466-
});
467-
468442
describe("When friendly errors are enabled", () => {
469443
let loadCopydeckFor;
470444
let registerAdapter;

src/components/Editor/Runners/PythonRunner/SkulptRunner/SkulptRunner.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
cpythonAdapter,
2424
friendlyExplain,
2525
} from "@raspberrypifoundation/python-friendly-error-messages";
26+
import ErrorMessage from "../../../ErrorMessage/ErrorMessage";
2627
import ApiCallHandler from "../../../../../utils/apiCallHandler";
2728
import store from "../../../../../redux/stores/WebComponentStore";
2829
import VisualOutputPane from "../VisualOutputPane";
@@ -89,6 +90,7 @@ const SkulptRunner = ({
8990
const user = useSelector((state) => state.auth.user);
9091
const isSplitView = useSelector((state) => state.editor.isSplitView);
9192
const isEmbedded = useSelector((state) => state.editor.isEmbedded);
93+
const isOutputOnly = useSelector((state) => state.editor.isOutputOnly);
9294
const codeRunTriggered = useSelector(
9395
(state) => state.editor.codeRunTriggered,
9496
);
@@ -638,6 +640,7 @@ const SkulptRunner = ({
638640
<RunnerControls skinny />
639641
)}
640642
</div>
643+
<ErrorMessage />
641644
<TabPanel key={0}>
642645
<pre
643646
className={`pythonrunner-console pythonrunner-console--${settings.fontSize}`}
@@ -674,6 +677,7 @@ const SkulptRunner = ({
674677
{!isEmbedded && showVisualOutput && <OutputViewToggle />}
675678
{!isEmbedded && isMobile && <RunnerControls skinny />}
676679
</div>
680+
{!isOutputOnly && <ErrorMessage />}
677681
<TabPanel key={0}>
678682
<VisualOutputPane ref={visualOutputPaneRef} />
679683
</TabPanel>

src/components/Editor/Runners/PythonRunner/SkulptRunner/SkulptRunner.test.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,61 @@ describe("When an error originates in the sense_hat shim", () => {
346346
});
347347
});
348348

349+
describe("When an error has occurred", () => {
350+
let mockStore;
351+
let store;
352+
let initialState;
353+
354+
beforeEach(() => {
355+
const middlewares = [];
356+
mockStore = configureStore(middlewares);
357+
initialState = {
358+
editor: {
359+
project: {
360+
components: [
361+
{
362+
name: "main",
363+
extension: "py",
364+
content: "boom!",
365+
},
366+
],
367+
image_list: [],
368+
},
369+
error: "SyntaxError: bad token T_OP on line 1 of main.py",
370+
},
371+
auth: {
372+
user,
373+
},
374+
};
375+
});
376+
377+
test("Displays error message", () => {
378+
store = mockStore(initialState);
379+
render(
380+
<Provider store={store}>
381+
<SkulptRunner active={true} />
382+
</Provider>,
383+
);
384+
385+
expect(
386+
screen.getByText("SyntaxError: bad token T_OP on line 1 of main.py"),
387+
).toBeVisible();
388+
});
389+
390+
test("Does not display error message when isOutputOnly state is true", () => {
391+
initialState.editor.isOutputOnly = true;
392+
store = mockStore(initialState);
393+
render(
394+
<Provider store={store}>
395+
<SkulptRunner active={true} />
396+
</Provider>,
397+
);
398+
expect(
399+
screen.queryByText("SyntaxError: bad token T_OP on line 1 of main.py"),
400+
).not.toBeInTheDocument();
401+
});
402+
});
403+
349404
describe("When there is an import error and the site is cross-origin isolated", () => {
350405
let store;
351406
beforeEach(() => {

src/components/Mobile/MobileProject/MobileProject.jsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const MobileProject = ({
2525
const codeRunTriggered = useSelector(
2626
(state) => state.editor.codeRunTriggered,
2727
);
28-
const error = useSelector((state) => state.editor.error);
2928
const includesInstructions = sidebarOptions.includes("instructions");
3029

3130
const [selectedTab, setSelectedTab] = useState(1);
@@ -42,12 +41,6 @@ const MobileProject = ({
4241
}
4342
}, [codeRunTriggered, sidebarShowing, withSidebar]);
4443

45-
useEffect(() => {
46-
if (!codeRunTriggered && error && projectType === "python") {
47-
setSelectedTab(withSidebar ? 1 : 0);
48-
}
49-
}, [error, codeRunTriggered, projectType, withSidebar]);
50-
5144
return (
5245
<div
5346
className="proj-container proj-editor-container proj-container--mobile"

src/components/Mobile/MobileProject/MobileProject.test.js

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -200,46 +200,3 @@ describe("When withSidebar is false", () => {
200200
expect(screen.queryByTitle("sidebar.expand")).not.toBeInTheDocument();
201201
});
202202
});
203-
204-
describe("When there is an error after code has been run", () => {
205-
beforeEach(() => {
206-
const initialState = {
207-
editor: {
208-
project: {
209-
project_type: "python",
210-
components: [
211-
{
212-
name: "main",
213-
extension: "py",
214-
content: "print('hello')",
215-
},
216-
],
217-
image_list: [],
218-
user_id: user.profile.user,
219-
},
220-
codeRunTriggered: false,
221-
openFiles: [["main.py"]],
222-
focussedFileIndices: [0],
223-
error: "An error occurred",
224-
},
225-
auth: {
226-
user: user,
227-
},
228-
};
229-
const store = mockStore(initialState);
230-
render(
231-
<Provider store={store}>
232-
<MobileProject withSidebar={true} sidebarOptions={["settings"]} />
233-
</Provider>,
234-
);
235-
});
236-
237-
test("The input tab is selected", () => {
238-
const inputTab = screen.getByText("mobile.code").parentElement;
239-
expect(inputTab).toHaveClass("react-tabs__tab--selected");
240-
});
241-
242-
test("The error message is displayed", () => {
243-
expect(screen.getByText("An error occurred")).toBeInTheDocument();
244-
});
245-
});

src/web-component.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696

9797
newWebComp.setAttribute("with_projectbar", "true");
9898
newWebComp.setAttribute("with_sidebar", "true");
99-
newWebComp.setAttribute("friendly_errors_enabled", "true");
10099
newWebComp.setAttribute(
101100
"sidebar_options",
102101
JSON.stringify([

0 commit comments

Comments
 (0)