Skip to content

Latest commit

 

History

History
77 lines (53 loc) · 2.43 KB

File metadata and controls

77 lines (53 loc) · 2.43 KB

Documentation

Hosted demo

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:

  1. A linkable row id for each example (URL hash)
  2. The example title and runtime
  3. The original code and traceback
  4. The friendly explanation generated by the library

Usage

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:

  1. Install the package and prepare the demo:
    npm install
    npm run prepare-demo

Then in the root directory of the project:

  1. Start up a local web server:

    npx http-server -p 8000
  2. Navigate to http://localhost:8000/docs

Local source switching (development only)

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.

Usage

(all commands should be run in the root directory of the project)

  1. Make sure the project is built:

    npm run build:all
    # or for continuous watching:
    npm run dev:build
  2. Start up a local web server:

    npx http-server -p 8000
  3. Navigate to one of:

    • http://localhost:8000/docs (vendored build)
    • http://localhost:8000/docs?local=true (local dist/ build)