Skip to main content

error_to_ariadne_report

Function error_to_ariadne_report 

Source
pub fn error_to_ariadne_report<'a>(
    err: &Error,
    filename: &'a str,
    source: &str,
) -> Report<'a, (&'a str, Range<usize>)>
Expand description

Convert a noyalib Error into an [ariadne::Report].

filename is the source identifier ariadne prints in the report header. source is the YAML input — its byte length is used to clamp the highlighted byte range so a stale or trimmed source never panics inside ariadne.

When the structured diagnostic has no source labels, the resulting report is a header-only message without a source label, matching the existing Error::format_with_source fallback.

§Examples

use noyalib::{from_str, Value};
use noyalib::ariadne_adapter::error_to_ariadne_report;
use ariadne::Source;

let source = "a: [unclosed";
let err = from_str::<Value>(source).unwrap_err();
let report = error_to_ariadne_report(&err, "input.yaml", source);
let mut out: Vec<u8> = Vec::new();
report.write(("input.yaml", Source::from(source)), &mut out).unwrap();
assert!(!out.is_empty());