SPB Git

Repository Public

diagnostics.md 5.1 KB 142 lines markdown

1<!--2ORIX Sonata3File: Documentation/manual/diagnostics.md4Author: Simon-Pierre Boucher5Contact: contact@spboucher.ai6-->7# Diagnostics89A diagnostic is what the compiler tells you about your code: an error that prevents10compilation, or a warning about something that compiles but probably is not what you meant.1112## Reading one1314```text15piece.sonata:4:23: error[S2001]: unknown instrument 'GrandPiana'164 |     instrument piano: GrandPiana {17  |                       ^^^^^^^^^^18  help: did you mean 'GrandPiano'?19```2021* `piece.sonata:4:23` — the file, the line and the column.22* `error` or `warning`, and a **code** that identifies the rule.23* The message, the line of source with the exact range underlined and, when the compiler has24  one, a suggestion.2526In the app, problems are underlined in the editor, marked in the gutter and listed in the27console. Click one to go to it. When the fix is mechanical and safe — a misspelt name with28one close match, for instance — the console offers a button that applies it.2930The compiler does not stop at the first problem: it recovers and reports what it can in one31pass, up to 200 diagnostics.3233## The families of codes3435| Prefix | Stage | Typical cause |36|---|---|---|37| `L0…` | reading the text | an unterminated string, an unknown character, a file that is too large |38| `P1…` | syntax | a missing brace, a statement in the wrong place, a reserved word used as a name |39| `S2…` | names | an unknown instrument, effect, preset, parameter or variable; a name defined twice |40| `T3…` | types and units | seconds added to beats, a value out of range, a missing unit |41| `M4…` | music | a note out of an instrument's range, a signature change inside a bar, a dangling tie |42| `G5…` | signal graphs | a feedback loop without a delay, buses routed in a circle |43| `Q6…` | limits | too many notes, endless recursion |44| `I7…` | modules | a module that cannot be found, an import cycle |4546Every code is documented in `Documentation/spec/diagnostics.md`, and a test checks that the47compiler emits no code that is missing from that list.4849## The ones you will meet5051**S2001 — unknown instrument.** The name after the colon is not an instrument of the standard52library or of your project.5354```sonata,error=S200155composition "S2001" {56    instrument a: Pianoforte {57        play C458    }59}60```6162**P1010 — a reserved word used as a name.** `out`, `play`, `tempo`, `chord` and the other63keywords cannot name variables. Note names cannot either: `A4` and `Bb` are always notes.6465**T3001 — an operator applied to the wrong types.** The message names both types.6667```sonata,error=T300168composition "T3001" {69    instrument a: GrandPiano {70        play C4 + 440Hz71    }72}73```7475**T3003 — a decimal where an exact duration is needed.** Write `3/8`, not `0.375`.7677**T3005 — a value outside its range.** The message gives the range.7879**T3006 — a missing or wrong unit.** A time parameter needs `ms`, `s` or a musical duration; a80frequency needs `Hz`.8182```sonata,error=T300683composition "T3006" {84    instrument a: GrandPiano {85        play C486        effects {87            eq(low_cut: 80)88        }89    }90}91```9293**S2022 and S2023 — unknown preset, unknown parameter.** Usually a typing mistake; the94suggestion names the closest match. The valid names are in the95[reference](reference/effects.md) and in `sonata docs NAME`.9697**M4001 — a note outside the instrument's range** (warning). The note is rendered anyway.9899**M4002 — a signature change inside a bar.** Finish the bar first, or declare the change at100composition level with `at`.101102```sonata,error=M4002103composition "M4002" {104    signature 4/4105    instrument a: GrandPiano {106        play C4107        signature 3/4108    }109}110```111112**M4005 — a tie with nothing to tie to** (warning). The next note of the same voice has113another pitch, or does not start where this one ends.114115**G5002 — a loop without a delay in a patch.** A node reads a node defined later. Route the116feedback through `delay(in: …)`.117118**Q6001 and Q6003 — too many notes, calls nested too deep.** Usually a loop or a recursion119that does not end where you expected.120121**I7001 — module not found.** `import a.b` looks for `a/b.sonata` beside the file being122compiled (in a project: under `src/`).123124## Warnings are worth reading125126A warning does not stop the piece from playing. It marks a place where what you wrote and what127you get may differ. A clean compilation — no error and no warning — is the normal state of a128finished piece; every example shipped with Sonata compiles without a single diagnostic.129130## Studio edits that no longer apply131132When the code changes under an edit made in the Studio, the edit is skipped rather than133applied to the wrong note. The console lists each one as *Studio edit skipped* with the134reason. See [Studio](studio.md#how-studio-edits-relate-to-the-code).135136## From the command line137138`sonata check file.sonata` prints diagnostics in the form above on standard error and exits139with 1 if there is an error. `--json` prints them as data — code, severity, message, file,140line, column, byte range, suggestion and fix — for editors and scripts. See141[Command line](cli.md#check).142
Files main
Menu

Theme