📝 yaml_error_context_hack
Returns the serde_yaml error location and message to pass to miette.
The location() reported in the error is incorrect, due to serde-yaml#153.
This does a best-effort to find the actual error source offsets from the Display string of the error.
Usage
Add the following to Cargo.toml
= "0.1.0"
In code:
use ;
use ;
let file_contents = r#"---
outer:
field_1: 123
# ^
# '--- field_2 missing the first character of the first type that has `#[serde(flatten)]`.
"#;
let error = .unwrap_err;
let error_and_context = new;
let loc_line = 3;
let loc_col = 3; // index 2 is column 3
assert_eq!;
assert_eq!;
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.