Fixes: https://github.com/zkat/miette/issues/408
Implement `WrapError` for `Option<T>`. This is inline with `anyhow` that
also implements `Context` for `Option<T>`.
The implementation requires us to introduce a `DisplayError` internal
only type, that creates an error from a type that only implements
`Display` (`Report::from_adhoc` requires the type to also implement
`Debug`, but `WrapError` only requires it to implement `Display`).
For this I copied `MessageError` and adapted it to implement `Debug`
using the underlying type's `Display` impl. This is a bit of a hack, but
anyhow does [something similar][1].
[1]: https://docs.rs/anyhow/latest/src/anyhow/wrapper.rs.html#34
* Fix `clippy::doc_lazy_continuation` lints
* Fix `dead_code` warnings in tests.
Protect code used in some tests based on features with feature
checks.
* Fix `clippy::needless_borrows_for_generic_args` lints
* Remove a useless conversion
* Remove a cfg_attr check for `track_caller`
This shouldn't be needed here as the test is already ignored.
Fixes: https://github.com/zkat/miette/issues/369
Diagnostic impls are no longer reset to default when converting a
`Report` into a `Box<dyn Diagnostic>`. Also prevented `Report` vtables
and handlers from being kept around on the heap after conversion.
This can be used to avoid awkward `start..(end + 1)` constructions,
which will trigger the `clippy::range_plus_one` lint.
I added a single impl for `InclusiveRange` rather than a blanket
`impl<T: RangeBounds> From<T> for SourceSpan` for two reasons. The first
is that the blanket impl would be a breaking change (because dependent
crates may currently define a type `T: RangeBounds` and also have `impl
From<T> for SourceSpan`). The second is that this would allow one-sided
ranges (`..x`, `x..`). In order to support bounded-below ranges, we
would need to change `SourceSpan` so that `length` may depend on the the
specific `SourceCode` instance. That seems like an unlikely use case.
This improves `get_lines()` logic by using a string-buffer with a capacity hint.
That avoids growing the buffer from zero each time, saving a bunch of reallocations.
* fix(docs): `alt` attribut for `single-line-example.png`
The white line breaks in the `alt` attribute prevented the `single-line-example.png` image from being displayed.
* Revert "fix(docs): `alt` attribut for `single-line-example.png`"
This reverts commit 2e97d568aa.
* fix: image link in `lib.rs` instead of `readme.md`
* feat(docs): cargo make readme
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.