Skip to content

Commit

Permalink
docs: add severity example (#350)
Browse files Browse the repository at this point in the history
Co-authored-by: hzlinyiyu <hzlinyiyu@corp.netease.com>
  • Loading branch information
attila-lin and hzlinyiyu-netease authored Feb 23, 2024
1 parent 328bf37 commit 62cfd22
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ pub struct MyErrorType {
}
```

##### ... help text
#### ... help text
`miette` provides two facilities for supplying help text for your errors:

The first is the `#[help()]` format attribute that applies to structs or
Expand Down Expand Up @@ -461,6 +461,19 @@ let err = Foo {
};
```

#### ... severity level
`miette` provides a way to set the severity level of a diagnostic.

```rust
use miette::Diagnostic;
use thiserror::Error;

#[derive(Debug, Diagnostic, Error)]
#[error("welp")]
#[diagnostic(severity(Warning))]
struct Foo;
```

#### ... multiple related errors

`miette` supports collecting multiple errors into a single diagnostic, and
Expand Down Expand Up @@ -635,7 +648,7 @@ then you may want to use [`miette!`], [`diagnostic!`] macros or

let source = "2 + 2 * 2 = 8".to_string();
let report = miette!(
labels = vec[
labels = vec![
LabeledSpan::at(12..13, "this should be 6"),
],
help = "'*' has greater precedence than '+'",
Expand Down

0 comments on commit 62cfd22

Please sign in to comment.