Skip to content

Use ariadne error reporting library for compile errors#2426

Open
neunenak wants to merge 14 commits intocasey:masterfrom
neunenak:use-ariadne
Open

Use ariadne error reporting library for compile errors#2426
neunenak wants to merge 14 commits intocasey:masterfrom
neunenak:use-ariadne

Conversation

@neunenak
Copy link
Copy Markdown
Contributor

@neunenak neunenak commented Oct 10, 2024

This commit starts introducing the ariadne rust error-reporting crate to just. In order to make individual commits a bit more tractable, this commit only introduces the new ariadne error formatting for compile errors, leaving other sorts of errors alone for the time being.

With the deliberately-broken justfile:

[group: ]
test_recipe:
    echo "TEST"

Running just now results in an error that looks like:

image

This commit also updates the minimum rust version to 1.85, since the latest version of ariadne also requires that minimum version to compile; in the process of porting the tests, I also noticed that a couple of tests, namely unknown_start_of_token_invisible_unicode and unknown_start_of_token_ascii_control_char, had raw unprintable ascii literals in the source file, which was causing some problems with e.g. running ripgrep on the file containing them. So I changed them to use unicode escapes instead. Apart from this, all the tests should be exactly the same as they were previously, except for testing for the new error formatting.

Pertains to #1323

@neunenak
Copy link
Copy Markdown
Contributor Author

I deliberately introduced a compile error, here's what that looks like currently:

just -l
error: Attribute `group` got 2 arguments but takes 1 argument
  ——▶ justfile:15:2
   │
15 │ [group('test', 'bogus extra argument')]
   │  ^^^^^

and here's what that looks like with ariadne as it's currently set up in that PR:

[01] Error: Attribute argument count mismatch
 ╭─[justfile:15:2]
 │
15 │ [group('test', 'bogus extra argument')]
 │  ──┬──
 │    ╰──── Found 2 arguments
 │
 │ Note: `group` takes 1 argument
────╯

slightly nicer I suppose

@casey
Copy link
Copy Markdown
Owner

casey commented Oct 10, 2024

Is the formatting off in that error message? It looks misaligned.

@neunenak
Copy link
Copy Markdown
Contributor Author

Is the formatting off in that error message? It looks misaligned.

Huh, yeah, must've happened when I copy-pasted it from the terminal, it looks fine there. Screenshot:
ariadne

And the current error message in the same terminal:

current

@neunenak
Copy link
Copy Markdown
Contributor Author

neunenak commented Oct 11, 2024

Another error:

duplicate

@casey
Copy link
Copy Markdown
Owner

casey commented Oct 12, 2024

Tentatively, I think this looks good. This will be a massive change though, because there are so many tests which check error messages.

I think the easiest way to do this would be to land a commit which switches to ariadne, but which doesn't change any error messages or try to add any additional highlights. I think we could write a script to automatically convert existing tests to the new format.

Then we could start improving the error messages one by one, by adding additional spans, etc.

Some questions:

  • Can "Error:" be made lowercase?
  • Can the error numbers (i.e. [E01]) be removed?
  • Can the underline be made red, to indicate that it's an error? (For existing errors, the underlined token is always an error, so it should be red, and then if we add additional spans, like hints, those could be a different color)

@neunenak
Copy link
Copy Markdown
Contributor Author

Tentatively, I think this looks good. This will be a massive change though, because there are so many tests which check error messages.

I think the easiest way to do this would be to land a commit which switches to ariadne, but which doesn't change any error messages or try to add any additional highlights. I think we could write a script to automatically convert existing tests to the new format.

Then we could start improving the error messages one by one, by adding additional spans, etc.

This makes sense

Some questions:

Can "Error:" be made lowercase?

Yeah. You have to do this in the kinda-silly way of defining ReportKind::Custom("error", Color::Red), and using that in place of ReportKind::Error when building the ariadne Report, but that works fine.

Can the error numbers (i.e. [E01]) be removed?

Yeah, that's totally optional. I kind of like the idea of having a rustc-style authoritative list of error codes, but that's not worth trying to merge in the first pass in any case.

Can the underline be made red, to indicate that it's an error? (For existing errors, the underlined token is always an error, so it should be red, and then if we add additional spans, like hints, those could be a different color)

Yeah there's an API for assigning pretty arbitrary colors to labels:

formatting

@casey
Copy link
Copy Markdown
Owner

casey commented Oct 12, 2024

Yeah. You have to do this in the kinda-silly way of defining ReportKind::Custom("error", Color::Red), and using that in place of ReportKind::Error when building the ariadne Report, but that works fine.

Dope.

Yeah, that's totally optional. I kind of like the idea of having a rustc-style authoritative list of error codes, but that's not worth trying to merge in the first pass in any case.

I like the idea of doing that too, although definitely later.

Can the underline be made red, to indicate that it's an error? (For existing errors, the underlined token is always an error, so it should be red, and then if we add additional spans, like hints, those could be a different color)

Yeah there's an API for assigning pretty arbitrary colors to labels:

Dope.

So yeah, I think this is a good change, although the search and replace for changing all the tests will be brutal.

@casey
Copy link
Copy Markdown
Owner

casey commented Nov 27, 2024

An idea that might make this easier: Can we style the adriane errors so that they look the same as just errors, which would let us merge this with minimal changes to the tests? We could follow up with PRs which improved the style using adriane features, which would require changing the tests, but hopefully could be entirely automated. This PR is likely to keep accumulating conflicts which might make it hard to land.

@neunenak
Copy link
Copy Markdown
Contributor Author

neunenak commented Dec 3, 2024

An idea that might make this easier: Can we style the adriane errors so that they look the same as just errors, which would let us merge this with minimal changes to the tests? We could follow up with PRs which improved the style using adriane features, which would require changing the tests, but hopefully could be entirely automated. This PR is likely to keep accumulating conflicts which might make it hard to land.

I'm not sure there's an easy way to make the error output look like just errors. I was having some trouble with tests not matching, which I realized was because ariadne was always emitting ansi color codes even in tests; so I added some functionality to pass color enable/disable to ariadne which solves that problem. Now it's just a matter of updating the tests, which I was trying to find a way to use an AI code editor to do. If not I'll write a script for it or do it manually.

neunenak and others added 5 commits February 24, 2026 00:01
Update all integration test stderr expectations to match ariadne's
output format, which uses '╭─[file:line:col]' and '───╯' instead of
the previous '——▶' and '^^^^' format.

Also remove unused `StrComparison` import from tests/test.rs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
neunenak and others added 7 commits February 24, 2026 02:32
Fix Report::build API change: the 3-argument form (kind, source_id, offset)
is now 2-argument (kind, span) where span is (source_id, range).

Update all test stderr expectations for the new format where the location
is wrapped with spaces: `╭─[ file:line:col ]` instead of `╭─[file:line:col]`.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When the max argument count is usize::MAX (representing no upper bound),
display "takes at least N argument(s)" instead of the literal
"takes between N and 18446744073709551615 arguments".

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace literal binary bytes (U+200B zero-width space and null byte) in
test source code with Rust escape sequences (\u{200b} and \0), making
tests/misc.rs a pure-ASCII file searchable by ripgrep and Neovim Telescope.

The escape sequences expand to the actual characters at runtime, so test
behavior is unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
neunenak and others added 2 commits February 24, 2026 16:56
The Windows constant for the recursion limit error was still using the old
`——▶` format. Update it to match ariadne's output format with the
column number (57) where Windows hits the recursion limit due to its
smaller default stack size.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@neunenak neunenak changed the title (WIP) Use ariadne Use ariadne error reporting library for compile errors Feb 25, 2026
@neunenak neunenak marked this pull request as ready for review February 25, 2026 01:14
@neunenak
Copy link
Copy Markdown
Contributor Author

@casey in the year or so since I last looked at this, LLMs got good enough to make the code changes in a (relatively) non-tedious way, so this PR is ready for review.

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.

2 participants