Improve friendly error message#1487
Conversation
…icitly rawTraceback contains `<exec>` instead of `main.py` as the filename, for example, we can now override the filename passed to friendlyExplain()
…iFoundation/editor-ui into 1448-and-ui-branches-combined
PFEM 0.6.0 markup has improved accessibility attributes, such as aria labels and roles. Has no effect on the styling (since classes, and the markup as a whole, remain the same).
…iFoundation/editor-ui into 1448-and-ui-branches-combined
There was a problem hiding this comment.
Pull request overview
Updates the Python error UI to support pfem v0.7.0 “friendly” error messages, and repositions error display so it appears in the input panel (and appropriately in output-only mode), including mobile tab-selection behavior.
Changes:
- Bumps
@raspberrypifoundation/python-friendly-error-messagesto0.7.0and updates runners to use the new adapter +sections: ["title","summary"]. - Introduces
FriendlyErrorMessageand refactorsErrorMessagestyling/markup; movesErrorMessagerendering intoEditorInput. - Adds/updates unit + Cypress coverage for friendly errors and mobile error-tab selection.
Reviewed changes
Copilot reviewed 25 out of 28 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
.yarnrc.yml |
Pre-approves the pfem package for Yarn’s restricted installs. |
package.json |
Bumps pfem dependency to 0.7.0. |
yarn.lock |
Lockfile update for pfem 0.7.0. |
src/web-component.html |
Web component test page formatting tweaks and attribute changes. |
src/utils/setupTests.js |
Updates Jest mock exports for pfem adapter changes. |
src/PyodideWorker.js |
Adds rawTraceback to worker error payload for friendlier parsing. |
src/components/Mobile/MobileProject/MobileProject.jsx |
Switches mobile tabs to input when Python errors occur after running. |
src/components/Mobile/MobileProject/MobileProject.test.js |
Adds tests for mobile error display/tab selection. |
src/components/Editor/Runners/PythonRunner/SkulptRunner/SkulptRunner.jsx |
Updates pfem adapter usage and friendlyExplain options; removes runner-local ErrorMessage rendering. |
src/components/Editor/Runners/PythonRunner/SkulptRunner/SkulptRunner.test.js |
Removes outdated error-message placement tests. |
src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx |
Updates pfem adapter usage; uses rawTraceback; shows ErrorMessage only in output-only mode. |
src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.test.js |
Updates error message expectations and adds friendly-error edge case tests. |
src/components/Editor/FriendlyErrorMessage/FriendlyErrorMessage.jsx |
New component to render sanitized friendly error HTML. |
src/components/Editor/FriendlyErrorMessage/FriendlyErrorMessage.test.js |
New tests for friendly error rendering + sanitization. |
src/components/Editor/ErrorMessage/ErrorMessage.jsx |
Refactors error UI markup; embeds FriendlyErrorMessage and icon. |
src/components/Editor/ErrorMessage/ErrorMessage.test.js |
Updates assertions for new class naming. |
src/components/Editor/EditorInput/EditorInput.jsx |
Renders ErrorMessage at the bottom of the input panel (above Run). |
src/components/Editor/EditorInput/EditorInput.test.js |
Adds a test asserting error message appears in EditorInput. |
src/assets/stylesheets/InternalStyles.scss |
Includes FriendlyErrorMessage styles in internal stylesheet bundle. |
src/assets/stylesheets/FriendlyErrorMessage.scss |
New styling for pfem HTML elements (title/summary/code/file/line). |
src/assets/stylesheets/ErrorMessage.scss |
Updates styling and class structure for new ErrorMessage layout. |
src/assets/stylesheets/EditorPanel.scss |
Formatting/cleanup only. |
src/assets/icons/cancel_FILL.svg |
New icon used in ErrorMessage header row. |
src/assets/error_file.svg |
New asset used to decorate file references in friendly errors. |
cypress/helpers/editor.js |
Updates selectors and adds helper for friendly error message container. |
cypress/fixtures/copydeck.json |
Adds a fixture copydeck for deterministic friendly-error Cypress tests. |
cypress/e2e/spec-wc-skulpt.cy.js |
Adds Cypress coverage for friendly errors in Skulpt. |
cypress/e2e/spec-wc-pyodide.cy.js |
Adds Cypress coverage for friendly errors in Pyodide. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| loadCopydeckFor(navigator.language || "en", { | ||
| base: `${process.env.PUBLIC_URL}/python-error-copydecks/`, | ||
| }); |
There was a problem hiding this comment.
We normally use locale from the i18n library rather than the navigator language - is this intentional here? I'm not sure if it will cause any problems - does loadCopydeckFor always fall back to en anyway?
| newWebComp.setAttribute("host_styles", JSON.stringify([])); | ||
| const scratchApiEndpoint = new URL(".", window.location.href) | ||
| .href | ||
| .replace(/\/$/, ""); | ||
| const scratchApiEndpoint = new URL( | ||
| ".", | ||
| window.location.href, | ||
| ).href.replace(/\/$/, ""); | ||
| newWebComp.setAttribute("scratch_api_endpoint", scratchApiEndpoint); | ||
|
|
||
| queryParams.forEach((value, key) => { |
There was a problem hiding this comment.
I don't understand the reasons for these changes and a few others - do you have your linter set up correctly in your editor? Or is there a reason this file wasn't properly linted before?
Just makes it a bit harder to see what you actually have changed
zetter-rpf
left a comment
There was a problem hiding this comment.
Great, I like the tests you've added - clear and easy to see what they are testing.
The PR was harder to review because there are a lot of changes across different files so it's harder for me to see that we're doing everything you said in the PR description - I don't think it's worth splitting out now, but for next time it could be helpful to think about how to break something like this up into logical commits and/or PRs as your working through it.
I added a couple of minor comments, but nothing blocking.
❗ This branch was created by rebasing #1485 to #1483.
How to enable friendly errors
friendly_errors_enabled: truetooptionsin src/components/Editor/Project/Project.jsxnewWebComp.setAttribute("friendly_errors_enabled", "true");tocreateWebComponentin src/web-component.htmlDecisions made upon adding pfem v. 0.7.0
titleandsummaryof friendly errors (potentiallywhybit might also be added later on)ErrorMessagenow optionally includesFriendlyErrorMessageErrorMessageto the bottom of input panel above Run buttonMobileProject), when the error is triggered after run, the input panel becomes the selected tab so that users can see the error (if no error triggered, the output panel becomes selected)WebcomponentProject.jsx, EditorInput is not rendered at all in output only mode, resulting inErrorMessagedisplayed only by Output panel of Pyodidemain.pyshows first.main.py, they will show (one at a time).WIP and future pfem
whyof friendly error, copy and UIScreen recordings of editor with friendly messages
Multiple python files
https://github.com/user-attachments/assets/a70727a4-121a-4c05-859f-f60f2cc29046
Responsiveness
https://github.com/user-attachments/assets/6697cfd4-fca9-4c04-af66-92b181a8e34d
Mobile screen (< 600 px)
https://github.com/user-attachments/assets/48736879-ff09-439d-8b1f-fb633a215333