miette
you FAIL miette? you fail her compiler like the unsafe C program? oh! oh! jail for mother! jail for mother for One Thousand Years!!!!
(I'm sorry, I'll come up with a better pun later.)
About
miette
is a diagnostic definition library for Rust. It includes a series of
protocols that allow you to hook into its error reporting facilities, and even
write your own error reports! It lets you define error types that can print out
like this (or in any format you like!):
|
|
|
|
The [Diagnostic] trait in miette
is an extension of std::error::Error
that
adds various facilities like [Severity], error codes that could be looked up
by users, and snippet display with support for multiline reports, arbitrary
[Source]s, and pretty printing.
While the miette
crate bundles some baseline implementations for [Source]
and [DiagnosticReporter], it's intended to define a protocol that other crates
can build on top of to provide rich error reporting, and encourage an
ecosystem that leans on this extra metadata to provide it for others in a way
that's compatible with [std::error::Error]
Installing
Using cargo-edit
:
Example and Guide
/*
First, you implement a regular `std::error::Error` type.
`thiserror` is a great way to do so, and plays extremely nicely with `miette`!
*/
use Error;
/*
Next, we have to implement the `Diagnostic` trait for it:
*/
use ;
/*
Then, we implement `std::fmt::Debug` using the included `MietteReporter`,
which is able to pretty print diagnostics reasonably well.
You can use any reporter you want here, or no reporter at all,
but `Debug` is required by `std::error::Error`, so you need to at
least derive it.
Make sure you pull in the `miette::DiagnosticReporter` trait!.
*/
use fmt;
use ;
/*
Now we can use `miette`~
*/
use ;
And this is the output you'll get if you run this program:
|
|
|
|
License
miette
is released to the Rust community under the MIT license.
It also includes some code taken from eyre
,
also under the MIT license.