Commit Graph

535 Commits

Author SHA1 Message Date
elkowar 2a7e32cdc7
feat: Add show_related_errors_as_nested 2024-12-22 22:56:17 +01:00
Akiomi KAMAKURA c7eeada1e0
docs: fix broken link (#415) 2024-12-08 09:33:24 -08:00
Kat Marchán b2011f693b
chore: Release 2024-11-26 20:01:39 -08:00
Kat Marchán 0c46c0b4d4
docs: update changelog 2024-11-26 20:00:13 -08:00
Jalil David Salamé Messina 7fae60fd84
feat(report): Implement `WrapError` for `Option` (#409)
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
2024-11-26 19:55:24 -08:00
George Pollard 465e6b6ab6
feat(graphical): Inherit source code to causes (#401) 2024-11-26 19:53:19 -08:00
Фаттахов Марат Русланович 68d47fa8b5
tests: Small refactor of doc tests (#396)
Move use NamedSource a bit up, since now it looks like it is not
imported.

Co-authored-by: Marat Fattakhov <m.fattakhov@yadro.com>
2024-11-26 19:50:56 -08:00
Kat Marchán 01564e070f
chore: Release 2024-11-26 00:44:33 -08:00
Kat Marchán fe068f6fc1
docs: update changelog 2024-11-26 00:43:02 -08:00
Gal Schlezinger 2902a2337c
docs(examples): add serde_json integration example (#407) 2024-11-13 09:57:24 -08:00
Bruce Mitchener 5f441d0115
fix(clippy): Fix `needless_return` lint. (#405)
This happens when building with `--features fancy`.
2024-09-26 09:32:58 -07:00
Cass Fridkin f3fb4c1ecd
feat(Diagnostic): Implement `Diagnostic` for `Infallible` (#402) 2024-09-25 10:30:33 -07:00
Bruce Mitchener d60c8f10f1
docs: Fix some broken links and missing backticks. (#399) 2024-09-25 10:29:12 -07:00
Bruce Mitchener 215f9aae33
docs: Fix typos (#398) 2024-09-25 10:28:30 -07:00
Bruce Mitchener 789a04e30d
fix(features): Use `dep:` syntax for dependencies in features. (#394)
This prevents creating implicit features for them which can be
confusing (and duplicates features).
2024-09-25 10:28:01 -07:00
Bruce Mitchener 21e9a70ad8
deps: Bump `terminal_size` to 0.4.0 (#404) 2024-09-25 10:14:22 -07:00
John Lewis 93d3bd118a
feat(Report): add `from_err()` method to `Report` (#403) 2024-09-06 23:56:01 -07:00
George Pollard d6b4558502
fix(graphical): Handle invalid UTF-8 in source code (#393)
* Handle invalid unicode in source

* Fix build on 1.70
2024-08-08 14:46:42 -07:00
Bruce Mitchener 15beec4330
fix(clippy): fix `clippy::doc_lazy_continuation` lints (#395)
* 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.
2024-08-06 10:12:06 -07:00
Jonathan Dygert bf5aa3742f
fix(graphical): Format entire link instead of just name (#389) 2024-07-11 16:04:28 -07:00
Brooks Rady bdd1d74614
fix(report): conversion into `Box<dyn Diagnostic>` (#370)
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.
2024-06-26 09:36:46 -07:00
Dániel Buga edfdcb525e
fix(handlers): Disable textwrap::smawk feature (#379) 2024-06-26 09:34:30 -07:00
Rintaro Itokawa 9bbcf3c601
fix(perf): mark error constructors cold (#378)
* refactor: mark error constructors cold

* refactor: remove `Send + Sync` impl
2024-06-26 09:33:42 -07:00
Benjamin Lee 73da45b65c
feat(SourceSpan): add impl From<InclusiveRange> (#385)
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.
2024-06-26 09:31:50 -07:00
Luca Bruno b8dfcda4a8
perf(handlers): optimize string-buffer reallocations (#387)
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.
2024-06-26 09:31:31 -07:00
Boshen e1026f75e0
fix(clippy): fix Rust v1.78.0 clippy warnings (#382) 2024-06-26 09:31:12 -07:00
Boshen 813232ba79
fix(color): setting NO_COLOR should not print ansi codes for non-terminals (#381)
Fixes: https://github.com/zkat/miette/issues/380
2024-06-11 09:18:24 -07:00
Sébastien Mischler b82cc81b8e
fix(docs): `alt` attribut for `single-line-example.png` (#372)
* 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
2024-05-01 15:20:01 -07:00
Will Bush ea4296dace
fix(clippy): Fix clippy lints in docs (#365)
* Fix commented out code in lib.rs docs not found in README.md

* Fix clippy lints in README.md and lib.rs
2024-04-12 23:11:30 -07:00
TrapinchO 97766e8d90
docs: fix up previous docs change a bit (#362) 2024-04-03 14:58:36 -07:00
TrapinchO 7b42b12c5f
fix(docs): updated example image (fixes #111) (#270) 2024-04-03 13:31:03 -07:00
Brooks Rady 3eabbcebf1
fix(graphical): fix nested error wrapping (#358)
Fixes: https://github.com/zkat/miette/issues/333
2024-03-27 16:20:06 -07:00
Kat Marchán ca646f3119
chore: Release 2024-03-07 12:21:32 -08:00
Kat Marchán ff7baae70c
docs: update changelog 2024-03-07 12:21:18 -08:00
Nahor 24a7bf4f4e
ci(doc consistency): check that lib.rs and README.md are consistent (#353) 2024-03-07 12:20:08 -08:00
Yiyu Lin 22b29eec38
docs: use `cargo readme` to update (#351) 2024-02-27 21:58:02 -08:00
Yiyu Lin 62cfd221ba
docs: add `severity` example (#350)
Co-authored-by: hzlinyiyu <hzlinyiyu@corp.netease.com>
2024-02-23 07:43:22 -08:00
Boshen 328bf37922
feat(wasm): add feature "fancy-no-syscall" for wasm targets (#349)
Fixes: https://github.com/zkat/miette/issues/346
2024-02-23 07:42:39 -08:00
Nahor 6ea86a2248
fix(redundant-import): fix a warning and CI failure in nightly (#348) 2024-02-21 14:05:17 -08:00
Nahor 7d9dfc6e8e
fix(invalid span): skip the snippet when read_span fails (#347)
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, ...)
2024-02-21 13:46:58 -08:00
Nahor 75fea0935e
fix(label-collections): Label collection fixes and cleanup (#343)
* 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.
2024-02-17 13:46:24 -08:00
Kat Marchán a18a6444d9
chore: Release 2024-02-15 18:18:45 -08:00
Kat Marchán dc77b0cb5b
docs: update changelog 2024-02-15 18:18:32 -08:00
Nahor 03060245d8
feat(collection): add support for collection of labels (#341)
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
2024-02-15 18:14:04 -08:00
Brooks Rady 6f09250cca
feat(source): derive common traits for NamedSource, SourceSpan, and SourceOffset (#340) 2024-02-08 14:16:49 -08:00
Brooks Rady c2f06f6cca
feat(derive): enable more boxed types to be #[diagnostic_source] (#338) 2024-02-07 10:20:18 -08:00
Brooks Rady 6e829f8c0c
fix(tests): revert test-breaking changes of e5c7ae4 (#339)
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
2024-02-07 10:17:42 -08:00
Kat Marchán ecb01022f0
chore: Release 2024-02-04 17:59:20 -08:00
Kat Marchán ea12e3f781
docs: update changelog 2024-02-04 17:59:06 -08:00
Kat Marchán a4011d174c
feat(deps): bump dependencies
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
2024-02-04 17:26:25 -08:00