Errors and diagnostics

Every refusal midad makes carries a code, a place in the file, a message, and where the checker knows it, the fix. A person reads that as the text report midad check prints; a program reads it as JSON.

The text report

$ midad check bad.md
bad.md:8:11
  × E0230: operator cannot combine float and number
    ╭─[bad.md:8:11]
  7 │ const r = 1.5;
  8 │ print(str(r + 1));
    ·           ──┬───
    ·             ╰── operator cannot combine float and number
  9 │ ```
    ╰────
  help: numbers and floats never mix implicitly; convert one side, for example
        `float(a) == b` or `int(b)`

The line and column point into the .md file you wrote, not into anything the compiler built. midad run prints the same report and refuses to run a program that has an error.

The JSON form

midad check --json prints one object:

{
  "command": "check",
  "diagnostics": [
    {
      "actual": null,
      "code": "E0230",
      "column": 11,
      "end_column": 16,
      "end_line": 8,
      "expected": null,
      "file": "bad.md",
      "fix": "numbers and floats never mix implicitly; convert one side, for example `float(a) == b` or `int(b)`",
      "line": 8,
      "message": "operator cannot combine float and number",
      "severity": "error"
    }
  ],
  "files": 1,
  "ok": false,
  "summary": { "errors": 1, "warnings": 0 }
}
  • ok is true when there are no errors. Warnings do not change it and do not change the exit code.
  • Every diagnostic has all ten fields. A field that does not apply is null, never absent, so a reader can rely on the shape.
  • file, line, column, end_line and end_column are 1-based.
  • expected and actual are short names, filled where the checker knows both sides; the rest carry null and the message says the same thing in prose.
  • fix is the same line the text report prints after help:.

midad run --json prints the same shape, with the program's own output in an output field.

Exit codes

code meaning
0 no errors
1 at least one error
2 the command itself was wrong: a path that does not exist, an unknown flag

--json changes what is printed, not the exit code.

Looking a code up

midad explain CODE prints one row of the table: the code, its severity, the message template and the fix. midad explain with no code prints all of them, and --json gives the same rows as objects.

The table is embedded in the binary and it is the same table docs/DIAGNOSTICS.md shows, so the answer a program gets and the answer a person reads cannot drift. The generated diagnostics index is that table rendered as pages, one per code, generated at build time.

A message template can carry {} where the checker fills in what it saw: the type it expected, the target it refused, the name it could not find.

Warnings

A warning is a real finding that does not stop the program:

code warning
W002 an import reaches outside the project directory
W004 a module name does not match its file name
W005 a function is not snake_case
W006 state is not snake_case
W007 an imported module is outside the conventional layout
W008 / on two integers looks like it was meant to be idiv
W009 a function with a fn parameter is never called, so its body is not checked

Runtime errors

A runtime error is not a diagnostic: the program was fine and then did something impossible. It aborts with a span and exit code 1, and it never panics:

overflow.md
---
midad: "0.1"
module: overflow
---

# overflow

```exec
let big = 9223372036854775807;
print(str(big + 1));
```
midad run (exit 1)
overflow.md:10:1
  × R0001: integer overflow
    ╭─[overflow.md:10:1]
  9 │ let big = 9223372036854775807;
 10 │ print(str(big + 1));
    · ──────────┬─────────
    ·           ╰── integer overflow
 11 │ ```
    ╰────

```output
integer overflow

The runtime errors are integer overflow, division by zero, a bad index, a wrong dynamic type, a step budget exhausted, and the size caps on strings, lists and file reads. A compiled program prints one line, midad runtime error: …, and exits 1. Nothing in the runtime produces an Err value: result is a type you build yourself, and a runtime error is not resumable.

The interpreter gives every program a step budget, so a runaway loop stops instead of hanging. An HTTP request gets 50 million steps. A native program has no step budget.

What a diagnostic cannot tell you

The checker is a type checker, not a proof. It does not know what a map holds, because a map holds any. It does not check that a template's holes match the values you pass unless the map is written out at the call. It does not know whether a SQL identifier you concatenated was safe. The limits page lists the rest.

On this page