mirror of https://github.com/zkat/miette.git
docs: update readme with new stuff
This commit is contained in:
parent
5fbcd53026
commit
5fd2765bf0
39
README.md
39
README.md
|
|
@ -3,23 +3,12 @@ coder! Error code for One Thousand Lines!
|
||||||
|
|
||||||
## About
|
## About
|
||||||
|
|
||||||
`miette` is a diagnostic definition library for Rust. It includes a series of
|
`miette` is a diagnostic library for Rust. It includes a series of protocols
|
||||||
protocols that allow you to hook into its error reporting facilities, and even
|
that allow you to hook into its error reporting facilities, and even write
|
||||||
write your own error reports! It lets you define error types that can print out
|
your own error reports! It lets you define error types that can print out like
|
||||||
like this (or in any format you like!):
|
this (or in any format you like!):
|
||||||
|
|
||||||
```sh
|
<img src="https://raw.githubusercontent.com/zkat/miette/main/images/serde_json.png" alt="miette rendering a serde_json error very nicely">
|
||||||
Error: Error[oops::my::bad]: oops it broke!
|
|
||||||
|
|
||||||
[bad_file.rs] This is the part that broke:
|
|
||||||
|
|
||||||
1 | source
|
|
||||||
2 | text
|
|
||||||
⫶ | ^^^^ this bit here
|
|
||||||
3 | here
|
|
||||||
|
|
||||||
﹦try doing it better next time?
|
|
||||||
```
|
|
||||||
|
|
||||||
The [Diagnostic] trait in `miette` is an extension of `std::error::Error` that
|
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
|
adds various facilities like [Severity], error codes that could be looked up
|
||||||
|
|
@ -35,7 +24,7 @@ While the `miette` crate bundles some baseline implementations for [Source]
|
||||||
and [DiagnosticReportPrinter], it's intended to define a protocol that other crates
|
and [DiagnosticReportPrinter], it's intended to define a protocol that other crates
|
||||||
can build on top of to provide rich error reporting, and encourage an
|
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
|
ecosystem that leans on this extra metadata to provide it for others in a way
|
||||||
that's compatible with [std::error::Error]
|
that's compatible with [std::error::Error].
|
||||||
|
|
||||||
## Installing
|
## Installing
|
||||||
|
|
||||||
|
|
@ -57,10 +46,9 @@ use miette::{Diagnostic, SourceSpan};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Error, Debug, Diagnostic)]
|
#[derive(Error, Debug, Diagnostic)]
|
||||||
#[error("oops it broke!")]
|
#[error("oops!")]
|
||||||
#[diagnostic(
|
#[diagnostic(
|
||||||
code(oops::my::bad),
|
code(oops::my::bad),
|
||||||
severity(Warning),
|
|
||||||
help("try doing it better next time?"),
|
help("try doing it better next time?"),
|
||||||
)]
|
)]
|
||||||
struct MyBad {
|
struct MyBad {
|
||||||
|
|
@ -112,18 +100,7 @@ fn pretend_this_is_main() -> Result<()> {
|
||||||
|
|
||||||
And this is the output you'll get if you run this program:
|
And this is the output you'll get if you run this program:
|
||||||
|
|
||||||
```sh
|
<img src="https://raw.githubusercontent.com/zkat/miette/main/images/single-line-example.png" alt="miette rendering a single-line error">
|
||||||
Error: Error[oops::my::bad]: oops it broke!
|
|
||||||
|
|
||||||
[bad_file.rs] This is the part that broke:
|
|
||||||
|
|
||||||
1 | source
|
|
||||||
2 | text
|
|
||||||
⫶ | ^^^^ this bit here
|
|
||||||
3 | here
|
|
||||||
|
|
||||||
﹦try doing it better next time?
|
|
||||||
```
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 64 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
Loading…
Reference in New Issue