Skip to content

feat[next]: Friendly error messages#2655

Open
havogt wants to merge 3 commits into
GridTools:mainfrom
havogt:next_friendly_error_messages
Open

feat[next]: Friendly error messages#2655
havogt wants to merge 3 commits into
GridTools:mainfrom
havogt:next_friendly_error_messages

Conversation

@havogt

@havogt havogt commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Makes gt4py.next DSL errors user-friendly: structured diagnostics that point at the offending source and suggest a fix, instead of plain message strings.

  • Extends DSLError in place with optional structured fields (label, related spans, notes, hints, per-subclass code).
  • A single renderer owns the on-screen shape: line-number gutter, carets, same-line related-span merge, multi-line capping, note/hint wrapping, and a graceful fallback when source text is unavailable.
  • Adds a catalogue of unsupported Python constructs, mapping each to a user-facing name and an actionable hint, with a fallback for uncatalogued nodes.
  • Upgrades the highest-frequency frontend errors: undefined symbol with "did you mean", boolean and mixed-precision operand mismatches, and and/or on fields.
  • Attaches toolchain context ("While processing the definition of ...") via PEP 678 add_note.
  • Adds an authoring guide at docs/development/next/error-messages.md, linked from CODING_GUIDELINES.md and src/gt4py/next/AGENTS.md.
  • Regression tests pin the rendered diagnostic text.

havogt added 3 commits June 12, 2026 15:52
Extend `DSLError` in place (backward compatible) with structured payload —
`label`, `related` spans, `notes`, `hints`, and a per-subclass `code` — so
diagnostics carry data, not pre-formatted strings. Rendering moves behind a
single owner, `formatting.format_diagnostic_parts` (line-number gutter,
carets, same-line related merge, multi-line capping, note/hint wrapping,
graceful degradation when source text is unavailable).

Add a catalogue (`_UNSUPPORTED_FEATURE_HINTS` in `ffront/dialect_parser.py`)
that maps rejected `ast` nodes to a user-facing construct name and actionable
hints, with a fallback for uncatalogued nodes. Upgrade the highest-frequency
frontend errors (undefined symbol with "did you mean", boolean/mixed-precision
binop mismatches, `and`/`or` on fields) to point at the smallest offending
span and suggest the supported alternative. Attach late toolchain context via
PEP 678 `add_note` (routed into structured `notes`) at the `func_to_foast`
seam. Pin the rendered text with UI regression tests in
`test_diagnostic_messages.py`.

The code stays on the Python 3.10 floor (`Self` from `eve.extended_typing`,
`add_note` as a method override); `TODO(havogt)` marks the >=3.12 cleanups.

Add an authoring guide, `docs/development/next/error-messages.md`, linked from
`CODING_GUIDELINES.md` and `src/gt4py/next/AGENTS.md` so contributors and
agents find it: structured-diagnostic principles, the `DSLError` data model,
a step-by-step recipe for adding/improving a diagnostic, the style delta over
the base error-message rules, and worked before/after examples.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant