Todo:
- Set up automated testing and publishing through GitHub Actions
- Accessibility of output HTML
A small, runtime-agnostic, library that explains Python error messages in a friendlier way, inspired by p5.js's Friendly Error System.
It can be used in browser-based editors (like RPF's Code Editor web component) or any environment that executes Python code through Skulpt or Pyodide.
- Parses and normalises errors from Skulpt or Pyodide (via adapters)
- Matches errors against a copydeck (JSON rules and templates)
- Copydeck-based explanations can be localised
- Returns structured explanations as well as ready-made HTML snippets
import {
loadCopydeckFor,
registerAdapter,
skulptAdapter,
pyodideAdapter,
friendlyExplain
} from "python-friendly-error-messages";
await loadCopydeckFor(navigator.language); // falls back to "en"
// register runtimes
registerAdapter("skulpt", skulptAdapter);
registerAdapter("pyodide", pyodideAdapter);
// later, when you have an error string and some code:
const result = friendlyExplain({
error: rawTracebackString,
code: editorCode
});
// result.html is a ready-made snippet
// or use result.title, result.summary, result.steps, result.patch, result.traceSee the demo for a full set of examples.
See CONTRIBUTING.md for detailed instructions.
In brief:
npm install
npm run build -- --watch
npm testCreate a clean build for distribution:
npm run build:all && npm run build:browser
Output files will be in dist/.
You can now import, and use it, elsewhere (see Usage notes).
The package is published to: https://github.com/RaspberryPiFoundation/python-friendly-error-messages/pkgs/npm/python-friendly-error-messages
npm publish