Fixes: https://github.com/zkat/miette/issues/219
When a snippet couldn't be read (typically because the span didn't fit
within the source code), it and the rest of the diagnostic were silently
dropped, which was confusing to the developer.
Now, in place of the snippet, print an error message with the name of
the failed label and the error it triggered, then proceed with the rest
of the diagnostic (footer, related, ...)
* feat(collection): add label(collection) documentation to lib.rs
* feat(collection): remove repeated formatting of label text
Because of a typo, the label text was being formatted multiple times per
label in a collection. With the fix, the text is formatted only once per
collection
* feat(collection): chain iterators rather than extend vector
Since we are going to iterate anyway, instead of growing the label vector,
chain the iterators. This should be more efficient.
In some cases, this also remove a compilation warning about the label
vector being unnecessarily mutable.
* feat(collection): remove unnecessary `OptionalWrapper`
- In a label collection, there is no need for a `None` label. One should
just not add that label
- Code wise it is also incorrect. The wrapper will be for a vector of
spans, not for individual spans. It happens to work anyway, but this was
not the intended use.
Fixes: https://github.com/zkat/miette/issues/315
Allow errors to have a number of labels determined at runtime.
An example of this is when the rust compiler labels all the arms of
a `match` expression when one of them has an incompatible type
To allow customization of the text for each label in a collection, add
support for using LabeledSpan in collections instead of just regular
spans
The commit e5c7ae4 seemed to (potentially erronously?) remove a number of
spaces following the left `|` bar of some graphical report handler tests.
That change had no effect on the `syntax_highlighter_on_real_file()`
test, presumably because the trailing whitespace is removed by
`strip_ansi_escapes::strip_str()`, but it did break the
`triple_adjacent_highlight()` and `non_adjacent_hightlight()` tests.
Restoring the spaces removed in e5c7ae4 fixes the failing tests on main.
* fix(ci): move from minimal-versions to direct-minimal-versions
Fixes: https://github.com/zkat/miette/issues/336
BREAKING CHANGE: This bumps owo-colors to 4.0, which is a breaking change because we expose its styles as part of the graphical renderer API
The default `GraphicalReportHandler` disables the printing of cause
chains for any inner errors (errors `related()` to a source diagnostic)
when it disables nested footer printing. This results in lost cause
chain information when printing with the default report handler.
Previously, these tests would have spurious failures when NO_COLOR or
FORCE_COLOR was set in the user's environment, since we weren't clearing
one variable before testing a value for the other one. The previous
version of the code also did not restore environment variable values on
panic, which could cause spurious failures in other tests after one test
fails.
Fixes: https://github.com/zkat/miette/issues/317
It turned out there were two really. One related to how many characters
were added for the arrowheads in the gutter, and one where the gutter
was extended to a number of characters, including ansi escape codes.
However, because ansi escape codes are rather big, there would never be
any extension since the system thought the string was already long
enough, even though you don't actually see the width of those codes.
Previous output looked like this:
---- single_line_with_wide_char_unaligned_span_empty stdout ----
Error: oops::my::bad
× oops!
╭─[bad_file.rs:2:4]
1 │ source
2 │ 👼🏼text
· ─▲
· ╰── this bit here
3 │ here
╰────
help: try doing it better next time?
Note that the .max(start + 1) term is still necessary in the nonempty
branch, since it's possible to have a nonempty span covering zero-width
text.
* remove uncessary if statement
start > end in all cases.