feat[next]: Friendly error messages#2655
Open
havogt wants to merge 3 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes gt4py.next DSL errors user-friendly: structured diagnostics that point at the offending source and suggest a fix, instead of plain message strings.