Skip to content

Commit 75f471d

Browse files
committed
chore: further copy fixes, highlight "patch" section as being experimental
1 parent cc3ebbb commit 75f471d

3 files changed

Lines changed: 17 additions & 14 deletions

File tree

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ A small library that explains Python error messages in a friendlier way, inspire
44

55
It can be used in browser-based editors (like RPF's [Code Editor web component](https://github.com/RaspberryPiFoundation/editor-ui)) or any environment that executes Python code through Pyodide or Skulpt.
66

7-
This library is currently **Pyodide-first**. The copydeck and demos are developed and verified against a pinned Pyodide version (see [`docs/pyodide-config.js`](docs/pyodide-config.js)), and the demo runs that Pyodide build live to show real tracebacks. Skulpt is still supported, both runtimes emit CPython-style tracebacks and share one adapter, but it is not the current priority, so error coverage is tuned to Pyodide's messages first.
7+
This library is currently **Pyodide-first**. The copydeck and demos are developed and verified against a pinned Pyodide version (see [`docs/pyodide-config.js`](docs/pyodide-config.js)), and the demo runs that Pyodide build live to show real tracebacks. Skulpt is still supported, both runtimes emit CPython-style tracebacks and share one adapter, but it is not the current priority.
88

99
## Features
1010

1111
- Parses and normalises errors from Pyodide or Skulpt (via a shared CPython-traceback adapter)
12-
- Matches errors against a copydeck (JSON rules and templates)
13-
- Copydeck-based explanations can be localised
14-
- Returns structured explanations as well as ready-made HTML snippets
12+
- Matches errors against a copydeck (containing rules and templates)
13+
- Copydeck-based explanations can be localised (and the copydeck contains prompts and context to help with this)
14+
- Returns structured explanations as well as ready-to-use HTML snippets
1515

1616
## Usage
1717

@@ -66,6 +66,8 @@ const result = friendlyExplain({
6666

6767
See the [demo](docs/README.md) for a full set of examples.
6868

69+
*Note:* The "patch" section contains a suggested code change to fix the error, but should be considered experimental at this stage.
70+
6971
## Accessibility
7072

7173
`result.html` is built to be accessible by default (with WCAG 2.1 AA in mind):

copydecks/en/copydeck.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,13 @@
232232
"IndentationError": {
233233
"variants": [
234234
{
235-
"title": "The indentation doesn't match",
236-
"summary": "All lines in a block must start in the same column. Fix around {{loc}}.",
237-
"why": "Python groups code by indentation. Mixing tabs and spaces or uneven indents breaks the block.",
235+
"title": "The indentation isn't right here",
236+
"summary": "Python uses the spaces at the start of a line to group code into blocks, and the spacing around {{loc}} doesn't fit. A line may be indented when it shouldn't be, or missing the indentation a block needs.",
237+
"why": "Lines in the same block must start in the same column, a block only opens after a line ending in a colon (:), and a line can't be indented for no reason.",
238238
"steps": [
239-
"Use 4 spaces per level (not tabs).",
240-
"Line up all lines in the block."
239+
"If a line is indented but nothing above it ends in a colon (:), remove the extra spaces.",
240+
"If a block was expected (after a line ending in :), indent its lines by the same amount.",
241+
"Keep spacing consistent - 4 spaces per level - and don't mix tabs and spaces."
241242
],
242243
"_placeholders": {
243244
"loc": "Where the indentation problem is, eg. line 7 in main.py"
@@ -251,10 +252,10 @@
251252
{
252253
"title": "These data types don't work together",
253254
"summary": "You're joining (concatenating) different kinds of data types. For example, a number (integer or float) and a word (string).",
254-
"why": "When using + to join text and variables together the variable must have a string data type.",
255+
"why": "Python's + means 'add' for numbers and 'join' for text, so both sides have to be the same kind. It can't add a number to a piece of text.",
255256
"steps": [
256-
"Cast the variable as a string data type.",
257-
"Change the variable to the right kind: int(\"3\") or str(7)."
257+
"To join them as text, convert the number with str(...).",
258+
"To add them as numbers instead, make sure neither side is text."
258259
]
259260
}
260261
]
@@ -297,7 +298,7 @@
297298
{
298299
"title": "This index position does not exist",
299300
"summary": "You are trying to use an index position that does not exist. The list is not that long.",
300-
"why": "In this list: myList[\"A\", \"B\", \"C\"] \"A\" has the index position 0, \"B\" has the index position 1 and \"C\" has the index position 2. Index position 3 does not exist.",
301+
"why": "Items are counted from 0. In myList = [\"A\", \"B\", \"C\"], \"A\" is at index 0, \"B\" at 1 and \"C\" at 2 - so the largest valid index is 2, and index 3 does not exist.",
301302
"steps": [
302303
"Check the length with len(the_list).",
303304
"Use an index position number smaller than len(the_list)."

src/engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const pickVariant = (trace: Trace, code: string | undefined, sections?: Section[
104104
let patch: string | undefined = undefined;
105105
if (trace.type === "AttributeError" && /\.push\s*\(/i.test(codeLine)) {
106106
patch = codeLine.replace(/\.push\s*\(/i, ".append(");
107-
} else if (trace.type === "NameError" && trace.name) {
107+
} else if (trace.type === "NameError" && trace.name && !/cannot access free variable|not associated with a value/i.test(trace.message || "")) {
108108
patch = `${trace.name} = 0\n${codeLine}`;
109109
} else if (trace.type === "SyntaxError" && /^(if|for|while|def|class|elif|else|try|except|with)\b/i.test(codeLine) && !/:$/.test(codeLine.trim())) {
110110
const trimmedCodeLine = codeLine.replace(/\s*$/, "");

0 commit comments

Comments
 (0)