From 936aa7f9423cfb966100ffe5c95b864bd5dd129d Mon Sep 17 00:00:00 2001 From: Jamie Benstead Date: Mon, 23 Nov 2026 10:38:04 +0000 Subject: [PATCH 1/5] Update link URLs --- src/utils/aiHintLinks.jsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/utils/aiHintLinks.jsx b/src/utils/aiHintLinks.jsx index d14e417a2..7847acde2 100644 --- a/src/utils/aiHintLinks.jsx +++ b/src/utils/aiHintLinks.jsx @@ -1,10 +1,9 @@ import { useTranslation } from "react-i18next"; -// TODO: replace with real URLs once available export const AI_HINT_LEARN_MORE_URL = - "https://help.editor.raspberrypi.org/hc/en-us"; + "https://help.editor.raspberrypi.org/hc/en-us/articles/55620760636564-How-Artificial-Intelligence-AI-hints-work-in-the-Code-Editor"; export const AI_HINT_FEEDBACK_URL = - "https://form.raspberrypi.org/f/code-editor-feedback"; + "https://form.raspberrypi.org/f/ai-powered-error-messages-feedback"; const NewTabLink = ({ href, children }) => { const { t } = useTranslation(); From 6f7ca404e6ba7e4d7ee5e85141ac5de7b64d6f5c Mon Sep 17 00:00:00 2001 From: Jamie Benstead <57325966+jamiebenstead@users.noreply.github.com> Date: Mon, 23 Nov 2026 13:23:23 +0000 Subject: [PATCH 2/5] 1982 move the error to the input panel (#1773) closes https://github.com/RaspberryPiFoundation/digital-editor-issues/issues/1982 ## What's changed - Python errors now show at the bottom of the input panel - The error takes up at most half the input panel's height and scrolls if longer - On mobile, the Code tab opens when an error occurs - Output-only embeds are unchanged: the error still shows in the output ## Screens ### Error image ### Error with AI helper (to show the 50% error max height) image ### UPDATE: Changed button to match designs image --- cypress/e2e/spec-wc-pyodide.cy.js | 45 +++++++++++- cypress/e2e/spec-wc-skulpt.cy.js | 71 +++++++++++++++++++ cypress/helpers/editor.js | 9 +++ src/assets/stylesheets/EditorInput.scss | 6 ++ src/assets/stylesheets/RunBar.scss | 4 ++ .../Editor/EditorInput/EditorInput.jsx | 5 ++ .../Editor/EditorInput/EditorInput.test.jsx | 30 ++++++++ .../PyodideRunner/PyodideRunner.jsx | 5 +- .../PyodideRunner/PyodideRunner.test.jsx | 30 ++++++++ .../SkulptRunner/SkulptRunner.jsx | 3 +- .../SkulptRunner/SkulptRunner.test.jsx | 6 +- .../Mobile/MobileProject/MobileProject.jsx | 7 ++ .../MobileProject/MobileProject.test.jsx | 55 ++++++++++++++ src/components/RunButton/RunBar.jsx | 2 +- src/components/RunButton/RunnerControls.jsx | 8 ++- .../RunButton/RunnerControls.test.jsx | 12 ++++ 16 files changed, 286 insertions(+), 12 deletions(-) diff --git a/cypress/e2e/spec-wc-pyodide.cy.js b/cypress/e2e/spec-wc-pyodide.cy.js index 271814ce2..8c6746a50 100644 --- a/cypress/e2e/spec-wc-pyodide.cy.js +++ b/cypress/e2e/spec-wc-pyodide.cy.js @@ -1,15 +1,18 @@ import { + ensureFilePanelOpen, getEditorShadow, getErrorLine, getErrorMessage, - getFriendlyErrorMessage, getFileButtonByName, + getFriendlyErrorMessage, + getInputPanel, + getOutputPanel, getProgramInput, getPyodideOutput, getPythonConsoleOutput, + getRunButton, getTextOutputTab, makeNewFile, - ensureFilePanelOpen, runCode, runProject, setCodeEditorContent, @@ -41,6 +44,14 @@ describe("Running the code with pyodide", () => { }); }); + it("shows errors in the input panel and not the output panel", () => { + runCode("print(a)"); + getInputPanel() + .find(".error-message__python") + .should("contain", "NameError"); + getOutputPanel().find(".error-message").should("not.exist"); + }); + it("runs a simple program", () => { runCode('print("Hello world")'); getPyodideOutput().should("not.contain.text", "Visual output"); @@ -352,3 +363,33 @@ describe("When friendly errors enabled with pyodide", () => { ); }); }); + +describe("Running the code with pyodide in an output-only embed", () => { + beforeEach(() => { + const params = new URLSearchParams(); + params.set("code", "print(a)"); + params.set("embedded", "true"); + params.set("output_only", "true"); + cy.visit({ + url: `${origin}?${params.toString()}`, + headers: { + "Cross-Origin-Opener-Policy": "same-origin", + "Cross-Origin-Embedder-Policy": "require-corp", + }, + }); + cy.window().then((win) => { + Object.defineProperty(win, "crossOriginIsolated", { + value: true, + configurable: true, + }); + }); + }); + + it("shows the error in the output panel", () => { + getRunButton().should("not.be.disabled"); + runProject(); + getPyodideOutput() + .find(".error-message__python") + .should("contain", "NameError"); + }); +}); diff --git a/cypress/e2e/spec-wc-skulpt.cy.js b/cypress/e2e/spec-wc-skulpt.cy.js index dc725246f..559bf81f8 100644 --- a/cypress/e2e/spec-wc-skulpt.cy.js +++ b/cypress/e2e/spec-wc-skulpt.cy.js @@ -2,12 +2,17 @@ import { getErrorLine, getErrorMessage, getFriendlyErrorMessage, + getInputPanel, + getMobileTab, + getOutputPanel, getP5Canvas, getPythonConsoleOutput, + getRunButton, getSkulptRunner, getSkulptTabByName, getTurtleOutput, runCode, + runProject, stopProject, } from "../helpers/editor.js"; @@ -31,6 +36,14 @@ describe("Running the code with skulpt", () => { }); }); + it("shows errors in the input panel and not the output panel", () => { + runCode("print(a)"); + getInputPanel() + .find(".error-message__python") + .should("contain", "NameError"); + getOutputPanel().find(".error-message").should("not.exist"); + }); + it("runs a simple program", () => { runCode("print('Hello world')"); @@ -232,3 +245,61 @@ describe("When friendly errors enabled with skulpt", () => { ); }); }); + +describe("Running the code with skulpt on mobile", () => { + beforeEach(() => { + cy.viewport(400, 800); + cy.visit(origin); + cy.window().then((win) => { + Object.defineProperty(win, "crossOriginIsolated", { + value: false, + configurable: true, + }); + }); + }); + + it("switches to the code tab when an error occurs", () => { + runCode("print(a)"); + getMobileTab("Code").should("have.attr", "aria-selected", "true"); + getInputPanel() + .find(".error-message__python") + .should("be.visible") + .and("contain", "NameError"); + }); +}); + +describe("Running the code with skulpt in an output-only embed", () => { + const urlFor = (splitView) => { + const params = new URLSearchParams(); + params.set("code", "import turtle\nprint(a)"); + params.set("embedded", "true"); + params.set("output_only", "true"); + params.set("output_split_view", splitView); + return `${origin}?${params.toString()}`; + }; + + const visitAndRun = (splitView) => { + cy.visit(urlFor(splitView)); + cy.window().then((win) => { + Object.defineProperty(win, "crossOriginIsolated", { + value: false, + configurable: true, + }); + }); + getRunButton().should("not.be.disabled"); + runProject(); + cy.get("#results").should("contain", "NameError"); + }; + + it("shows the error in the output panel in split view", () => { + visitAndRun("true"); + getSkulptRunner() + .find(".error-message__python") + .should("contain", "NameError"); + }); + + it("does not show the error in tabbed view", () => { + visitAndRun("false"); + getSkulptRunner().find(".error-message").should("not.exist"); + }); +}); diff --git a/cypress/helpers/editor.js b/cypress/helpers/editor.js index 26a443ec7..2d5a78a9a 100644 --- a/cypress/helpers/editor.js +++ b/cypress/helpers/editor.js @@ -69,6 +69,15 @@ export const getTurtleOutput = () => getEditorShadow().find("#turtleOutput"); export const getErrorMessage = () => getEditorShadow().find(".error-message__python"); +export const getInputPanel = () => + getEditorShadow().findByRole("region", { name: "Input panel" }); + +export const getOutputPanel = () => + getEditorShadow().findByRole("region", { name: "Output panel" }); + +export const getMobileTab = (name) => + getEditorShadow().find(".mobile-nav").contains('[role="tab"]', name); + export const getErrorLine = () => getEditorShadow().find(".cm-error-line"); export const getFriendlyErrorMessage = () => diff --git a/src/assets/stylesheets/EditorInput.scss b/src/assets/stylesheets/EditorInput.scss index 2441f0098..2e2427de8 100644 --- a/src/assets/stylesheets/EditorInput.scss +++ b/src/assets/stylesheets/EditorInput.scss @@ -6,6 +6,12 @@ inline-size: 100%; } +.editor-input .error-message { + box-sizing: border-box; + flex-shrink: 0; + max-block-size: 50%; +} + .editor-input__view-only-banner { font-weight: var(--font-weight-bold); padding: var(--space-0-5) var(--space-1); diff --git a/src/assets/stylesheets/RunBar.scss b/src/assets/stylesheets/RunBar.scss index 94c0e3a18..72a32600b 100644 --- a/src/assets/stylesheets/RunBar.scss +++ b/src/assets/stylesheets/RunBar.scss @@ -4,6 +4,10 @@ flex-direction: row; justify-content: flex-end; padding: var(--space-1); + + .runner-controls { + padding: 0; + } } .--light { diff --git a/src/components/Editor/EditorInput/EditorInput.jsx b/src/components/Editor/EditorInput/EditorInput.jsx index bf746898e..e13b83f66 100644 --- a/src/components/Editor/EditorInput/EditorInput.jsx +++ b/src/components/Editor/EditorInput/EditorInput.jsx @@ -15,6 +15,7 @@ import EditorPanel from "../EditorPanel/EditorPanel"; import DraggableTab from "../DraggableTabs/DraggableTab"; import DroppableTabList from "../DraggableTabs/DroppableTabList"; import RunBar from "../../RunButton/RunBar"; +import ErrorMessage from "../ErrorMessage/ErrorMessage"; import "../../../assets/stylesheets/EditorInput.scss?inline"; import RunnerControls from "../../RunButton/RunnerControls"; @@ -31,6 +32,7 @@ const EditorInput = () => { const dispatch = useDispatch(); const isMobile = useMediaQuery({ query: MOBILE_MEDIA_QUERY }); const readOnly = useSelector((state) => state.editor.readOnly); + const isPythonProject = project?.project_type !== "html"; const [numberOfComponents, setNumberOfComponents] = useState( project?.components?.length, @@ -186,6 +188,9 @@ const EditorInput = () => { /> ))} + {isPythonProject && panelIndex === openFiles.length - 1 && ( + + )} {isMobile ? null : } ))} diff --git a/src/components/Editor/EditorInput/EditorInput.test.jsx b/src/components/Editor/EditorInput/EditorInput.test.jsx index 068ce3238..c39b22b82 100644 --- a/src/components/Editor/EditorInput/EditorInput.test.jsx +++ b/src/components/Editor/EditorInput/EditorInput.test.jsx @@ -185,6 +185,36 @@ describe("When not read only", () => { }); }); +describe("Error message", () => { + test("Shows error inside the input panel, above the run bar", () => { + setMedia({ width: "1000px" }); + renderEditorInput({ + editor: { ...initialState.editor, error: "NameError: boom" }, + }); + const error = screen.getByText("NameError: boom").closest(".error-message"); + expect(error.closest(".editor-input")).toBeInTheDocument(); + expect(error.nextElementSibling).toHaveClass("run-bar"); + }); + + test("Does not show anything when there is no error", () => { + renderEditorInput({}); + expect( + document.querySelector(".editor-input .error-message"), + ).not.toBeInTheDocument(); + }); + + test("Does not show error for HTML projects", () => { + renderEditorInput({ + editor: { + ...initialState.editor, + project: { ...initialState.editor.project, project_type: "html" }, + error: "Something went wrong", + }, + }); + expect(screen.queryByText("Something went wrong")).not.toBeInTheDocument(); + }); +}); + describe("When read only", () => { beforeEach(() => { renderEditorInput({ editor: { ...initialState.editor, readOnly: true } }); diff --git a/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx b/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx index 39f1f46c4..5e1c0de35 100644 --- a/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx +++ b/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx @@ -64,6 +64,7 @@ const PyodideRunner = ({ const user = useSelector((s) => s.auth.user); const userId = user?.profile?.user; const isSplitView = useSelector((s) => s.editor.isSplitView); + const isOutputOnly = useSelector((s) => s.editor.isOutputOnly); const isEmbedded = useSelector((s) => s.editor.isEmbedded); const reactAppApiEndpoint = useSelector((s) => s.editor.reactAppApiEndpoint); const codeRunTriggered = useSelector((s) => s.editor.codeRunTriggered); @@ -612,7 +613,7 @@ const PyodideRunner = ({ ref={output} > - + {isOutputOnly && } )} @@ -649,7 +650,7 @@ const PyodideRunner = ({ ref={output} > - + {isOutputOnly && } )} diff --git a/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.test.jsx b/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.test.jsx index aa376092c..a44ec30b1 100644 --- a/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.test.jsx +++ b/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.test.jsx @@ -27,6 +27,7 @@ import { openFile, setFocussedFileIndex, setFriendlyError, + setIsOutputOnly, } from "../../../../../redux/EditorSlice.js"; import store from "../../../../../app/store"; @@ -686,6 +687,35 @@ describe("When an error is received", () => { }); }); +describe("Error message in the output panel", () => { + beforeEach(() => { + act(() => { + store.dispatch(setError("NameError: boom")); + }); + }); + + test("is not shown by default", () => { + render( + + + , + ); + expect(screen.queryByText("NameError: boom")).not.toBeInTheDocument(); + }); + + test("is shown when output only", () => { + act(() => { + store.dispatch(setIsOutputOnly(true)); + }); + render( + + + , + ); + expect(screen.getByText("NameError: boom")).toBeInTheDocument(); + }); +}); + describe("When the code run is interrupted", () => { let input; diff --git a/src/components/Editor/Runners/PythonRunner/SkulptRunner/SkulptRunner.jsx b/src/components/Editor/Runners/PythonRunner/SkulptRunner/SkulptRunner.jsx index 7c1dac080..b64c73f90 100644 --- a/src/components/Editor/Runners/PythonRunner/SkulptRunner/SkulptRunner.jsx +++ b/src/components/Editor/Runners/PythonRunner/SkulptRunner/SkulptRunner.jsx @@ -678,7 +678,7 @@ const SkulptRunner = ({ ref={output} > - + {isOutputOnly && } )} @@ -718,7 +718,6 @@ const SkulptRunner = ({ ref={output} > - {!isOutputOnly && } )} diff --git a/src/components/Editor/Runners/PythonRunner/SkulptRunner/SkulptRunner.test.jsx b/src/components/Editor/Runners/PythonRunner/SkulptRunner/SkulptRunner.test.jsx index a28d5c41e..20cdf25ba 100644 --- a/src/components/Editor/Runners/PythonRunner/SkulptRunner/SkulptRunner.test.jsx +++ b/src/components/Editor/Runners/PythonRunner/SkulptRunner/SkulptRunner.test.jsx @@ -525,7 +525,7 @@ describe("When an error has occurred", () => { }; }); - test("Displays error message", () => { + test("Does not display error message in the output panel", () => { store = mockStore(initialState); render( @@ -534,8 +534,8 @@ describe("When an error has occurred", () => { ); expect( - screen.getByText("SyntaxError: bad token T_OP on line 1 of main.py"), - ).toBeVisible(); + screen.queryByText("SyntaxError: bad token T_OP on line 1 of main.py"), + ).not.toBeInTheDocument(); }); test("Does not display error message when isOutputOnly state is true", () => { diff --git a/src/components/Mobile/MobileProject/MobileProject.jsx b/src/components/Mobile/MobileProject/MobileProject.jsx index 8992147d5..81bb292d2 100644 --- a/src/components/Mobile/MobileProject/MobileProject.jsx +++ b/src/components/Mobile/MobileProject/MobileProject.jsx @@ -25,6 +25,7 @@ const MobileProject = ({ const codeRunTriggered = useSelector( (state) => state.editor.codeRunTriggered, ); + const error = useSelector((state) => state.editor.error); const aiHintToggleFocusRequested = useSelector( (state) => state.editor.aiHintToggleFocusRequested, ); @@ -56,6 +57,12 @@ const MobileProject = ({ } }, [codeRunTriggered, sidebarShowing, withSidebar]); + useEffect(() => { + if (error) { + setSelectedTab(withSidebar ? 1 : 0); + } + }, [error, withSidebar]); + return (
{ expect(screen.queryByTitle("sidebar.expand")).not.toBeInTheDocument(); }); }); + +describe("When an error occurs", () => { + const buildState = (error) => ({ + editor: { + project: { + project_type: "python", + components: [ + { name: "main", extension: "py", content: "print('hello')" }, + ], + image_list: [], + }, + codeRunTriggered: true, + openFiles: [["main.py"]], + focussedFileIndices: [0], + error, + }, + auth: {}, + }); + + test("switches from the output tab to the code tab", () => { + const { rerender } = render( + + + , + ); + const codeTab = screen.getByText("mobile.code").closest("li"); + const outputTab = screen.getByText("mobile.output").closest("li"); + expect(outputTab).toHaveAttribute("aria-selected", "true"); + + rerender( + + + , + ); + expect(codeTab).toHaveAttribute("aria-selected", "true"); + }); + + test("does not change tab when the error is cleared", () => { + const { rerender } = render( + + + , + ); + const outputTab = screen.getByText("mobile.output").closest("li"); + fireEvent.click(outputTab); + expect(outputTab).toHaveAttribute("aria-selected", "true"); + + rerender( + + + , + ); + expect(outputTab).toHaveAttribute("aria-selected", "true"); + }); +}); diff --git a/src/components/RunButton/RunBar.jsx b/src/components/RunButton/RunBar.jsx index 10eff8ec0..a209b4f1c 100644 --- a/src/components/RunButton/RunBar.jsx +++ b/src/components/RunButton/RunBar.jsx @@ -6,7 +6,7 @@ import "../../assets/stylesheets/RunBar.scss?inline"; const RunBar = ({ embedded = false }) => { return (
- +
); }; diff --git a/src/components/RunButton/RunnerControls.jsx b/src/components/RunButton/RunnerControls.jsx index c82ad02ba..de7b92bb1 100644 --- a/src/components/RunButton/RunnerControls.jsx +++ b/src/components/RunButton/RunnerControls.jsx @@ -9,7 +9,11 @@ import { stopCodeRun, stopDraw, triggerCodeRun } from "../../redux/EditorSlice"; import { runStoppedEvent } from "../../events/WebComponentCustomEvents"; import "../../assets/stylesheets/RunnerControls.scss?inline"; -const RunnerControls = ({ embedded = false, skinny = false }) => { +const RunnerControls = ({ + embedded = false, + skinny = false, + small = false, +}) => { const codeRunTriggered = useSelector( (state) => state.editor.codeRunTriggered, ); @@ -86,7 +90,7 @@ const RunnerControls = ({ embedded = false, skinny = false }) => { className={classNames("btn--primary", { "btn--run": !isRunning, "btn--stop": isRunning, - "btn--small": skinny, + "btn--small": skinny || small, })} disabled={ !isRunning && diff --git a/src/components/RunButton/RunnerControls.test.jsx b/src/components/RunButton/RunnerControls.test.jsx index cbe1977c7..bf11625b2 100644 --- a/src/components/RunButton/RunnerControls.test.jsx +++ b/src/components/RunButton/RunnerControls.test.jsx @@ -31,6 +31,18 @@ test("Run button shows when code is not running", () => { expect(runButton).toBeInTheDocument(); }); +test("Run button is small when small is set", () => { + const store = mockStore({ editor: {} }); + render( + + + , + ); + const runButton = screen.getByText("runButton.run").closest("button"); + expect(runButton).toHaveClass("btn--small"); + expect(runButton.parentElement).not.toHaveClass("btn-outer"); +}); + test("Stop button shows when code is running", () => { const initialState = { editor: { From ce4f12a7c44ee9847c2fe76b954ec3c1191ecd38 Mon Sep 17 00:00:00 2001 From: Jamie Benstead Date: Mon, 23 Nov 2026 16:26:35 +0000 Subject: [PATCH 3/5] Add tracking event to AI hint Learn more link --- .../Editor/AiErrorMessage/AiErrorMessage.jsx | 17 +++++- .../AiErrorMessage/AiErrorMessage.test.jsx | 58 +++++++++++++++++++ .../AiHintToggle/AiHintToggle.jsx | 20 ++++++- .../AiHintToggle/AiHintToggle.test.jsx | 32 ++++++++++ src/events/WebComponentCustomEvents.js | 3 + src/utils/aiHintLinks.jsx | 12 ++-- 6 files changed, 132 insertions(+), 10 deletions(-) diff --git a/src/components/Editor/AiErrorMessage/AiErrorMessage.jsx b/src/components/Editor/AiErrorMessage/AiErrorMessage.jsx index e937fe259..a7bbd571c 100644 --- a/src/components/Editor/AiErrorMessage/AiErrorMessage.jsx +++ b/src/components/Editor/AiErrorMessage/AiErrorMessage.jsx @@ -7,8 +7,9 @@ import BadgeQuestionMarkIcon from "../../../assets/icons/badge_question_mark.svg import SettingsIcon from "../../../assets/icons/settings.svg"; import { openAiHintSettings } from "../../../redux/EditorSlice"; import ApiCallHandler from "../../../utils/apiCallHandler"; -import { aiHintLinkComponents } from "../../../utils/aiHintLinks"; +import { getAiHintLinkComponents } from "../../../utils/aiHintLinks"; import { + aiHintLearnMoreLinkClickedEvent, aiHintRequestedEvent, aiHintTurnOffLinkClickedEvent, } from "../../../events/WebComponentCustomEvents"; @@ -105,6 +106,16 @@ const AiErrorMessage = () => { ); }; + const handleLearnMoreClick = () => { + document.dispatchEvent( + aiHintLearnMoreLinkClickedEvent({ + projectIdentifier, + errorDetails, + source: "errorMessage", + }), + ); + }; + return (
{(hint || failed) && ( @@ -137,7 +148,9 @@ const AiErrorMessage = () => {