#error-message #syn #diagnostics #miette #pretty #wrapper

syn-miette

A syn::Error wrapper that provides pretty diagnostic messages using miette

3 releases (breaking)

0.3.0 Apr 8, 2024
0.2.0 Mar 17, 2024
0.1.0 Oct 4, 2023

#1 in #miette

Download history 3/week @ 2024-02-20 15/week @ 2024-02-27 4/week @ 2024-03-05 109/week @ 2024-03-12 35/week @ 2024-03-19 2/week @ 2024-03-26 99/week @ 2024-04-02 52/week @ 2024-04-09

184 downloads per month
Used in 2 crates

MIT/Apache

15KB
245 lines

A syn::Error wrapper that provides pretty diagnostic messages using miette.

Usage

let source = r"
pub struct {
    num_yaks: usize
}";

let error = syn::parse_str::<syn::DeriveInput>(source).unwrap_err();
let error = syn_miette::Error::new(error, source);

assert_eq!(
    error.render(), // only with `--feature render`
"  × expected identifier
   ╭─[2:12]
 1 │
 2 │ pub struct {
   ·            ┬
   ·            ╰── expected identifier
 3 │     num_yaks: usize
   ╰────
"
);

Notably, Error properly renders children that have been syn::Error::combine-ed:

  × duplicate definition of `Foo`
   ╭─[1:8]
 1 │ struct Foo;
   ·        ─┬─
   ·         ╰── initial definition here
 2 │ enum Bar {}
 3 │ union Foo {}
   ·       ─┬─
   ·        ╰── duplicate definition of `Foo`
   ╰────

Dependencies

~0.7–1.7MB
~35K SLoC