The default `textwrap::WordSeparator::UnicodeBreakProperties` provides
sensible line breaking for (e.g.) emojis and CJK text. Unfortunately, it
also considers punctuation like `/` to be an appropriate location for
line breaks. This is fine for normal text, but leads to very bad
behavior when attempting to wrap error messages. Here, a file path is
broken across multiple lines (with box drawing characters added in
between parts of the path as well), making it impossible to copy-paste
the path out of the error message:
```
Error: × Failed to read Buck2 event log from `buck2 build //aaa/aaaa` via /var/folders/z5/fclwwdms3r1gq4k4p3pkvvc00000gn/
│ T/.tmpBgvlUI/buck-log.jsonl.gz
╰─▶ failed to open file `/var/folders/z5/fclwwdms3r1gq4k4p3pkvvc00000gn/T/.tmpBgvlUI/buck-log.jsonl.gz`: No such
file or directory (os error 2)
```
In the future, we may want to write our own line break algorithm that
breaks between CJK codepoints and emojis but not at punctuation like
slashes. For now, I believe it will be better to break lines at ASCII
spaces only.
Similar changes are made for some other settings:
- The default for `break_words` has been changed to `false` for similar
reasons.
- The default `textwrap::WordSplitter` has been changed to not split
words at existing hyphens, to prevent splits like `--foo-bar` into
`--foo-` and `bar`.
* style(clippy): quickly fix up clippy lints
* refactor(miette): remove `thiserror` from `error.rs`
* fix(fancy): `fancy` no longer depends on `derive`
Before this change, the `fancy` feature required the `derive` feature to
compile. Despite this, `derive` was not listed as a required feature to
use `fancy`. This meant that building with:
`cargo build --no-default-features --features fancy` would result in a
compilation error!
Now `fancy` can be used without `derive` enabled, and another use of
`thiserror` has been removed!
* refactor(miette): remove `thiserror` from `into_diagnostic.rs`
* refactor(miette): reuse `DiagnosticError` in `protocol.rs`
* refactor(miette): make `thiserror` a dev-dependency
* fix(miette): correctly forward error sources
* fix(miette): match `TestError` visibility with `mod tests`
* fix(miette): maintain 1.70 MSRV
* fix(miette): another fix for MSRV 1.70
* docs(miette): sync README and `rustdoc`
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