Commit Graph

242 Commits

Author SHA1 Message Date
cgettys-microsoft 2b79495c79
fix(ci, clippy): raise MSRV to 1.82, fix rust 1.90 warnings (#451)
* fix: remove unused code

* fix: 1.90 errors

* MSRV: 1.82.0

* fix: warnings exposed by increasing MSRV
2025-09-29 09:43:02 -07:00
Daniel Levin 51ca022b1f
docs: Include #[diagnostic(forward(..)] in documentation (#446) 2025-09-25 21:11:28 -07:00
Brooks Rady 521ef91f77
fix(deps): miette can now be used without syn (#436)
* 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`
2025-04-26 11:34:21 -07:00
nogiro 59c81617de
feat(deps): update `thiserror` from 1.0.56 to 2.0.11 (#426) 2025-03-01 18:04:51 -08:00
Gabriel Levcovitz 58d9f12411
fix(highlight): increase syntax highlighter config priority (#424)
Fixes: https://github.com/zkat/miette/issues/337
2025-03-01 17:58:58 -08:00
Elijah Hartvigsen f2ef693d1c
feat(labels): add support for disabling the primary label line/col information (#419) 2025-03-01 17:56:47 -08:00
Gabriel Levcovitz 9ba6fad769
fix(clippy): elide lifetimes (#423) 2025-03-01 17:52:07 -08:00
unbyte 1e1938a099
fix(graphical): prevent leading newline when no link/code (#418) 2025-01-14 14:01:44 -08:00
ElKowar 771a07519f
feat(graphical): support rendering related diagnostics as nested (#417)
Fixes: https://github.com/zkat/miette/issues/416
2024-12-22 14:06:11 -08:00
Akiomi KAMAKURA c7eeada1e0
docs: fix broken link (#415) 2024-12-08 09:33:24 -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
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
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
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
Yiyu Lin 22b29eec38
docs: use `cargo readme` to update (#351) 2024-02-27 21:58:02 -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
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
David Calavera c7144ee513
feat(fancy): Add option to change the link display text (#335)
This option allows to globally change the default `(link)` display text with any other text provider by users.
2024-02-04 16:54:18 -08:00
Kat Marchán ab7c066e76
fix(highlighter): ugh, missed another spot 2024-02-03 20:25:23 -08:00
Kat Marchán 1fa7f5241f
fix(fmt): remove nightly-only fmt flags 2024-02-03 20:14:01 -08:00
Kat Marchán 8b46679c36
fix(graphical): oops. Fix theme issue 2024-02-03 20:12:46 -08:00
Kat Marchán ab59a7bc9b
feat(MSRV): Actually bump the MSRV to 1.70.0 2024-02-03 19:59:57 -08:00
Kat Marchán 4c48584f30
feat(deps): remove once_cell dep in favor of `std::sync::OnceLock`
BREAKING CHANGE: This requires an MSRV bump to 1.70.0.
2024-02-03 19:50:33 -08:00
Kat Marchán e5c7ae469e
feat(deps): remove is-terminal dep in favor of `std::io::IsTerminal` 2024-02-03 19:50:30 -08:00
Adam Curtis e65d0a78cc
feat(highlighting): add syntax highlighting support with syntect crate (#313) 2024-02-03 19:47:46 -08:00
Adam Curtis 1df3b1a537
feat(source): Allow inner source type of a NamedSource to be borrowed (#254)
BREAKING CHANGE: This makes the `NamedSource` type generic over its `Source` type, instead of boxing it.
2024-02-03 19:40:17 -08:00
Gavrilikhin Daniil fad0e76ad2
feat(source): use `usize` for length (#265)
BREAKING CHANGE: This changes `SourceSpan`'s length type to `usize`.
2024-02-03 19:38:00 -08:00