Repository Public
1<!--2ORIX Sonata3File: Documentation/spec/diagnostics.md4Author: Simon-Pierre Boucher5Contact: contact@spboucher.ai6-->7# Sonata 0.1 — diagnostics89Every diagnostic has a stable code, a severity, a source span, a message, and when possible a10suggestion and a *fix* (a text edit that is safe to apply automatically). Codes never change11meaning; a retired code is never reused. A test checks that this page lists every code the12toolchain can emit.1314`sonata check --json` and the editor expose the same structure (`sonata_ir::Diagnostic`):15`code`, `severity`, `span {file, start, end}` (byte offsets), `message`, `suggestion`,16`fix {title, span, replacement}`, `related [{span, message}]`, plus a resolved `location`17(file name, 1-based line and column).1819When a file has lexical or syntax errors, semantic analysis is not reported for that20compilation: the tree is incomplete and its errors would be noise. Fix the syntax first.2122## L0xxx — lexer2324| Code | Meaning | Fix offered |25|---|---|---|26| L0001 | Unexpected character (a run of them is reported once). | |27| L0002 | A string is not closed before the end of its line. | insert `"` |28| L0003 | A block comment `/* … */` is never closed. | |29| L0004 | Unknown unit suffix glued to a number (`12bmp`). | the unit with the same letters (`BPM` → `bpm`) |30| L0005 | Invalid escape sequence in a string. | |31| L0006 | Integer literal does not fit in 64 bits. | |32| L0007 | Source larger than 4 MiB. | |33| L0008 | Source is not valid UTF-8. | |3435## P1xxx — parser3637| Code | Meaning | Fix offered |38|---|---|---|39| P1001 | Expected a statement, an item or an instrument member; found something else. | closest keyword at top level |40| P1002 | Expected a specific token (`{`, `:`, `=`, a name, …). | insert the token |41| P1003 | A block, list, parenthesis or argument list is never closed. | insert the closer |42| P1004 | Blocks or expressions nested deeper than 96 levels. | |43| P1005 | Expected an expression; or a parameter or setting has no value. | |44| P1006 | A signature is not two integers (`signature 4/4`). | |45| P1007 | Unknown modifier after `play` / `chord`. | closest modifier |46| P1008 | Invalid version line (`sonata 0.1`). | |47| P1009 | Item not allowed here (`import`, `fn`, `pattern`, `composition` below top level; `model`, `preset`, `graph`, `node`, `out` outside an instrument definition). | |48| P1010 | A reserved word is used as a name. | |49| P1011 | A note or pitch-class literal (`A4`, `Bb`) is used as a name. | |50| P1012 | A graph has more than one `out`. | |51| P1013 | Two statements on one line without `;`. | insert `;` |5253## S2xxx — symbols, scopes, registry names5455| Code | Meaning | Fix offered |56|---|---|---|57| S2001 | Unknown name: variable, function, instrument, bus, mode, chord quality, articulation, curve, or an effect that the strip does not have. | closest known name |58| S2002 | A name is defined twice at top level, or redefines a built-in. | |59| S2003 | A name is used as the wrong kind of thing (a function as a value, a pattern in an expression, a value as an instrument). | |60| S2004 | Unknown type in an annotation. | closest type |61| S2005 | Wrong arguments: count, unknown or repeated name, positional after named, unnamed argument where names are required. | closest parameter |62| S2006 | A top-level constant depends on itself. | |63| S2007 | Assignment to a constant or to a top-level definition. | |64| S2008 | Statement not allowed in this context (`play` in a bus, `return` in a track, …). | |65| S2009 | Unknown setting, clip option or `default` in this context. | closest setting |66| S2010 | No composition has the requested title. | |67| S2011 | A track or a bus is declared twice. | |68| S2012 | Instrument inheritance cycle. | |69| S2020 | Unknown engine model. | closest model |70| S2021 | Unknown effect. | closest effect |71| S2022 | Unknown preset of an engine or effect. | closest preset |72| S2023 | Unknown parameter or slot of an engine or effect. | closest parameter |73| S2024 | Value is not one of the choices of a parameter. | closest choice |74| S2025 | An instrument definition has no `model` (own or inherited). | |75| S2026 | Unknown patch node, or unknown port of a node. | closest name |76| S2027 | A derived instrument tries to change the model it inherits. | |7778## T3xxx — types and units7980| Code | Meaning | Fix offered |81|---|---|---|82| T3001 | Operator applied to incompatible types (`1s + 1/4`, `D4 + 2`), wrong operand type. | |83| T3002 | Wrong argument type for a built-in function. | |84| T3003 | A musical duration was expected (seconds or a float were given). | |85| T3004 | A pitch or a list of pitches was expected by `play` / `chord`. | add octave to a pitch class |86| T3005 | Value outside the documented range of a parameter, setting or function. | |87| T3006 | Wrong dimension for a parameter or setting (a number where dB, Hz, a time or an interval is required, …). | append the unit to a literal |88| T3007 | Division by zero. | |89| T3008 | List index out of range, or an empty list where an element is needed. | |90| T3009 | Value does not match its type annotation; a function does not return its declared type on every path. | |91| T3010 | The type exists in the language but is not a value type in 0.1 (`Signal`, `Instrument`, …). | |92| T3011 | A condition is not a `Bool`. | |93| T3012 | `for` over something that is not a list or a range. | |94| T3013 | Unknown member (`xs.size`), unknown `note.` value in a graph. | closest name |95| T3014 | The parameter cannot be automated. | |9697## M4xxx — musical validation9899| Code | Severity | Meaning |100|---|---|---|101| M4001 | warning | Note outside the playable range of the instrument (rendered anyway; at most 5 per track). |102| M4002 | error | Signature change not on a bar line. |103| M4003 | error | Tempo outside [1, 1000] bpm, or invalid tempo map. |104| M4004 | error | Two different tempos set at the same position. |105| M4005 | warning | A tie has no continuation (no adjacent note of the same pitch in the same voice). |106| M4006 | error | Swing ratio outside [50 %, 75 %]. |107| M4007 | error | Invalid signature (numerator 1–64, denominator a power of two up to 64). |108| M4008 | error | Velocity outside [0, 1]. |109| M4009 | error | Zero or negative duration (note, rest, ramp, swing unit). |110| M4010 | error | Negative position. |111| M4011 | error | Automation or bend points out of time order, or an automation without point. |112| M4012 | error | Unsupported sample rate. |113| M4013 | error | `peak_limit` outside [-60, 0] dBFS. |114| M4014 | warning | The composition has no track. |115| M4015 | error | Invalid tuplet numbers. |116| M4016 | error | `tuning` outside [220, 880] Hz. |117| M4018 | error | `degree()` used without a `key`. |118119(M4017 was never assigned.)120121## G5xxx — DSP graphs122123| Code | Meaning |124|---|---|125| G5001 | Bus routing forms a loop, or a bus is routed to itself. The loop is listed in the message. |126| G5002 | A patch node reads a node computed later without going through `delay(in: …)`; aliases that only refer to each other. |127| G5003 | A `graph` has no `out`. |128| G5004 | `graph` used with a model other than `patch`, or `model patch` without a graph. |129| G5005 | Operation not available between signals (division by a signal; the engine lacks the node an operator needs). |130| G5006 | Expression that cannot be used with signals (comparison, list, …). |131| G5007 | The graph output is a constant, a note value or a control-rate signal instead of audio. |132| G5008 | A constant-only port is driven by a signal. |133| G5009 | Node defined twice, or named `note`. |134| G5010 | A strip is routed to a bus that does not exist (only reachable with a hand-built Program). |135| G5011 | Warning: a named patch node does not reach the output; it is removed from the instrument. |136| G5099 | Internal error: the generated graph failed its own validation. Please report it. |137138## Q6xxx — quotas139140Defaults in parentheses; all configurable through `CompileOptions::quotas`. A quota error141stops the compilation cleanly at the statement that crossed the limit.142143| Code | Limit |144|---|---|145| Q6001 | Notes in a composition (1 000 000). |146| Q6002 | Evaluation steps (10 000 000). |147| Q6003 | Call depth (64), or combined nesting of blocks, calls and expressions (4 096). |148| Q6004 | List length (100 000). |149| Q6005 | Exact musical time overflowed 64-bit rationals. Never wraps. |150| Q6006 | Tracks (256). |151| Q6007 | Nodes in a patch (4 096). |152| Q6008 | Diagnostics (200): analysis stops instead of flooding. |153154## I7xxx — imports, modules, assets155156| Code | Meaning | Fix offered |157|---|---|---|158| I7001 | Module not found. | closest standard module |159| I7002 | Import cycle (the chain is listed). | |160| I7003 | Imports nested deeper than 16 levels. | |161| I7004 | The file asks for a newer language version than the toolchain implements. | |162| I7005 | Unsafe asset path in `clip` (absolute, `..`, backslash, control character, empty component). | |163