miette
miette copied to clipboard
Group related diagnostics visually
I understand that this can be a controversial change, so this is very much a suggestion. The idea would be to group related errors so that end-user understands what exactly caused the problems they've encountered.
An example from the tests:
Error: oops::my::bad
× oops!
╭─[bad_file.rs:1:1]
1 │ source
2 │ text
· ──┬─
· ╰── this bit here
3 │ here
╰────
help: try doing it better next time?
╭─There were 2 related diagnostics:
├─ 1.Error: oops::my::bad
│
│
│ × oops!
│ ╭─[bad_file.rs:1:1]
│ 1 │ source
│ · ───┬──
│ · ╰── this bit here
│ 2 │ text
│ ╰────
│ help: try doing it better next time?
│ ╭─There were 1 related diagnostics:
│ ├─ 1.Error: oops::my::bad
│ │
│ │
│ │ × oops!
│ │ ╭─[bad_file.rs:1:1]
│ │ 1 │ source
│ │ · ───┬──
│ │ · ╰── this bit here
│ │ 2 │ text
│ │ ╰────
│ │ help: try doing it better next time?
│ │ ├─There were 0 related diagnostics:
│ │
│
├─ 2.Error: oops::my::bad
│
│
│ × oops!
│ ╭─[bad_file.rs:1:1]
│ 1 │ source
│ · ───┬──
│ · ╰── this bit here
│ 2 │ text
│ ╰────
│ help: try doing it better next time?
│ ├─There were 0 related diagnostics:
│
Several considerations from a user that would benefit greatly from this change:
- "There were 1 related diagnostics" => "There was 1 related diagnostic"
- "1.Error" => "1. Error"
- As @LukeMathWalker pointed out, remove the "related" lead line if there are no related errors.
- I still think this is too verbose for my use case. It may be worth the consideration of making the "related errors" style configurable for the GraphicalReportHandler and introduce some other styles. I'm especially thinking of an alternate, fully inline style (like what is currently done, but without just listing the different errors).
I also think it'd be nice to be able group related errors better. The way related errors are displayed right now, each error seem completely independent, which make them actually seem unrelated.
Here's (very) roughly what one of my use case look like:
× A runtime error occurred
Error:
× Cannot add a number to a bool
╭─[5:1]
5 │ fn b($n)
6 │ $n + a()
· ─┬ ┬ ─┬─
· │ │ ╰── number
· │ ╰── invalid operation
· ╰── bool
7 │ end
╰────
Error: code
× error originated from here
╭─[8:1]
8 │ fn c($n)
9 │ b($n)
· ──┬──
· ╰── error originated here
10 │ end
╰────
Error: code
× error originated from here
╭─[10:1]
10 │ end
11 │ c(true)
· ───┬───
· ╰── error originated here
12 │
╰────
As you can see, it's rather unclean that these errors are related.
Regarding this issue I see that it's still unsure what direction to take.
I find the current proposal rather verbose, and in my case I think it'd look much better just without the Error: ...
clause. If there was an easy way to remove them, it'd make related errors more... related.