🪄 Srcerr
User friendly errors from source data.
This crate provides a SourceError type, which is formatted like Rust's compiler errors. Consumers are responsible for providing the correct byte and character indices, and line and column numbers.
Color support is enabled by default.
Demo
Suggestions
error: `chosen` value `ghi` is invalid.
-/source_ref_hint.yaml:6:9
|
6 | chosen: "ghi"
| ^^^^^
= note: expected one of: `abc`, `def`
help: `chosen` value must come from one of `available` values:
-/source_ref_hint.yaml:2:1
|
2 | available:
4 | - "def"
|
Long Expressions
error: Value `150` is invalid.
-/mnt/data/work/github/azriel91/srcerr/examples/long_expr_context.json:1:101
|
1 | .. "p":150, ..
| ^^^
| |
| 101
|
= hint: expected value to be less than 26
Usage
Sample usage can be seen in the examples.
cargo run --example simple
cargo run --example source_ref_hint
cargo run --example long_expr_context
cargo run --example html > /tmp/index.html
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.