Skip to content

Improve Error Messages and Diagnostics #10

@Kinflou

Description

@Kinflou

Improve Error Messages and Diagnostics

Priority

P2 (Medium) - Developer experience

Labels

  • dx
  • error-handling
  • diagnostics
  • P2

Estimated Effort

2 weeks

Description

Create rich, helpful compiler diagnostics using the ariadne crate. Good error messages are critical for developer experience.

Current State

Location: core/src/report.rs

Error reporting module exists but has todo!() placeholder and is underutilized throughout the codebase.

TODO References

  • report.rs:53 - todo!()

Examples of Good Error Messages

Current (Bad)

Error: Failed to compile schema

Desired (Good)

error: undefined type `Uesr`
  ┌─ example.ids:5:12
  │
5 │     user: Uesr
  │            ^^^^ not found in this scope
  │
  = help: did you mean `User`?

Acceptance Criteria

  • Source location tracking throughout compilation
  • Beautiful error messages with ariadne for:
    • Parse errors
    • Semantic errors
    • Type errors
    • Import errors
  • "Did you mean?" suggestions for typos
  • Multiple errors shown (don't stop at first)
  • Warning system for non-critical issues
  • Documentation of common errors with solutions

Tasks

Infrastructure

  • Add Span tracking to all AST nodes
  • Thread source locations through compilation
  • Create error types with location info
  • Integrate ariadne for rendering

Error Categories

  • Parse errors: syntax mistakes, invalid tokens
  • Semantic errors: undefined symbols, duplicate names
  • Type errors: type mismatches, invalid operations
  • Import errors: missing files, circular imports
  • Version errors: incompatible versions, breaking changes

Enhancements

  • Add "did you mean?" for common typos (Levenshtein distance)
  • Multi-error reporting (collect all errors, not just first)
  • Warning levels (error, warning, note)
  • Colored output (using ariadne's auto-color feature)
  • JSON output mode for IDE integration

Documentation

  • Document common errors with examples
  • Create error code system (E001, E002, etc.)
  • Add links to documentation in errors

Example Implementation

use ariadne::{Report, ReportKind, Label, Source};

Report::build(ReportKind::Error, source_id, span.start)
    .with_message("undefined type")
    .with_label(
        Label::new((source_id, span))
            .with_message("not found in this scope")
            .with_color(Color::Red)
    )
    .with_help("did you mean `User`?")
    .finish()
    .print((source_id, Source::from(source_code)))

Dependencies

Blocks

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Priority 2 - MediumdiagnosticsDiagnosticsdxDeveloper experienceerror-handlingError handling

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions