🪄 Srcerr

Crates.io CI Coverage Status

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

``rust error[E1]:chosenvalueghiis invalid. --> examples/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: --> examples/sourcerefhint.yaml:2:1 | 2 | available: | ---------- hint: first defined here 3 | - "abc" 4 | - "def" | ```

Long Expressions

rust error[E1]: 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

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.