fix: harden Claro diagnostics and runtime guards
Preserve source locations, validate malformed JSON, and add opt-in resource limits. Include executable error-guide coverage, learner pilot materials, native Windows acceptance helpers, and updated CI/documentation.
This commit is contained in:
+127
-12
@@ -1,29 +1,144 @@
|
||||
# Claro Errors
|
||||
# Errors and small repairs
|
||||
|
||||
Claro tries to report mistakes in beginner-friendly language.
|
||||
An error starts with `filename:line:`. Open that file and find that line.
|
||||
The line belongs to the function or imported file where the error happened,
|
||||
not automatically to the caller. Caught errors expose the same origin through
|
||||
`LASTERRORFILE` and `LASTERRORLINE`.
|
||||
|
||||
Examples:
|
||||
Use `claro check my_program.claro` for command/block mistakes; running the
|
||||
program also detects runtime expression/value errors. A checker is not a sandbox.
|
||||
The examples below are executed by `tools/validate_error_guide.py`.
|
||||
|
||||
## Quote
|
||||
|
||||
Save as `quote.claro`. Run `claro quote.claro`.
|
||||
|
||||
```claro
|
||||
SAY "Start"
|
||||
SAY "unfinished
|
||||
```
|
||||
|
||||
Message:
|
||||
|
||||
```text
|
||||
I do not know the command "PRNT". Did you mean "SAY"?
|
||||
quote.claro:2: Text is missing a closing quote. Add a double quote at the end.
|
||||
```
|
||||
|
||||
One repair:
|
||||
|
||||
```claro
|
||||
SAY "Start"
|
||||
SAY "finished"
|
||||
```
|
||||
|
||||
## Operand
|
||||
|
||||
Save as `operand.claro`. Run `claro operand.claro`.
|
||||
|
||||
```claro
|
||||
SET score 1
|
||||
SAY score +
|
||||
```
|
||||
|
||||
Message:
|
||||
|
||||
```text
|
||||
SET needs TO.
|
||||
Try:
|
||||
SET name TO "Alex"
|
||||
operand.claro:2: This expression needs a value after the operator.
|
||||
```
|
||||
|
||||
One repair:
|
||||
|
||||
```claro
|
||||
SET score 1
|
||||
SAY score + 1
|
||||
```
|
||||
|
||||
## Command
|
||||
|
||||
Save as `command.claro`. Run `claro check command.claro`.
|
||||
|
||||
```claro
|
||||
PRNT "Hello"
|
||||
```
|
||||
|
||||
Message:
|
||||
|
||||
```text
|
||||
IF block opened here is missing ENDIF
|
||||
command.claro:1: I do not know the command "PRNT". Did you mean "SAY"?
|
||||
```
|
||||
|
||||
One repair:
|
||||
|
||||
```claro
|
||||
SAY "Hello"
|
||||
```
|
||||
|
||||
## Assignment
|
||||
|
||||
Save as `assignment.claro`. Run `claro check assignment.claro`.
|
||||
|
||||
```claro
|
||||
SET name
|
||||
```
|
||||
|
||||
Message:
|
||||
|
||||
```text
|
||||
I do not know the variable "socre" yet. Did you mean "score"?
|
||||
assignment.claro:1: SET needs a name and a value. Try: SET name "Alex"
|
||||
```
|
||||
|
||||
For safer learning, run this before running a new program:
|
||||
One repair:
|
||||
|
||||
```bash
|
||||
./claro check my_program.claro
|
||||
```claro
|
||||
SET name "Alex"
|
||||
SAY name
|
||||
```
|
||||
|
||||
## Choice
|
||||
|
||||
Save as `choice.claro`. Run `claro check choice.claro`.
|
||||
|
||||
```claro
|
||||
IF YES
|
||||
SAY "Yes"
|
||||
```
|
||||
|
||||
Message:
|
||||
|
||||
```text
|
||||
choice.claro:1: IF block opened here needs END
|
||||
```
|
||||
|
||||
One repair:
|
||||
|
||||
```claro
|
||||
IF YES
|
||||
SAY "Yes"
|
||||
END
|
||||
```
|
||||
|
||||
## Variable
|
||||
|
||||
Save as `variable.claro`. Run `claro variable.claro`.
|
||||
|
||||
```claro
|
||||
SET score 10
|
||||
SAY socre
|
||||
```
|
||||
|
||||
Message:
|
||||
|
||||
```text
|
||||
variable.claro:2: I do not know the variable "socre" yet.
|
||||
```
|
||||
|
||||
One repair:
|
||||
|
||||
```claro
|
||||
SET score 10
|
||||
SAY score
|
||||
```
|
||||
|
||||
These teach short `SET` and `END`. Older forms remain supported in
|
||||
[compatibility syntax](COMPATIBILITY.md), not required as repairs.
|
||||
For a caught error, read its metadata before another error changes it.
|
||||
|
||||
Reference in New Issue
Block a user