https://raspberrypifoundation.github.io/python-friendly-error-messages/
This directory contains a demo index.html file that showcases the Python Friendly Error Messages library. This uses a given build of the library.
The demo shows how the library transforms common Python error traces (from both Skulpt and Pyodide runtimes) into friendly, beginner-friendly explanations. It includes examples of:
- NameError: Undefined variables
- SyntaxError: Missing colons and syntax issues
- AttributeError: Wrong method names (e.g.,
.push()instead of.append()) - TypeError: Type mismatches
- UnboundLocalError: Variables used before assignment
- IndexError: List index out of range
- KeyError: Dictionary key not found
- ZeroDivisionError: Division by zero
The demo renders a full-width table with:
- A linkable row id for each example (URL hash)
- The example title and runtime
- The original code and traceback
- The friendly explanation generated by the library
This is handled automatically on the hosted demo, but to run it locally against a specific version of the library:
Set the version of the library in docs/package.json, then in this docs/ directory run:
- Install the package and prepare the demo:
npm install npm run prepare-demo
Then in the root directory of the project:
-
Start up a local web server:
npx http-server -p 8000
-
Navigate to
http://localhost:8000/docs
When running locally, the demo shows a source switch bar at the top:
- default: vendored build (
docs/vendor/...) - local mode: local build (
dist/index.browser.js) via?local=true
Local mode can be used to test changes to the library on-the-fly, as long as you have a local build running (eg. via npm run dev:build).
On hosted environments (including GitHub Pages), the source switch UI is hidden and the demo always uses the vendored build.
(all commands should be run in the root directory of the project)
-
Make sure the project is built:
npm run build:all # or for continuous watching: npm run dev:build -
Start up a local web server:
npx http-server -p 8000
-
Navigate to one of:
http://localhost:8000/docs(vendored build)http://localhost:8000/docs?local=true(localdist/build)