Skip to main content

spanned_error_with_context

Function spanned_error_with_context 

Source
pub fn spanned_error_with_context<T, U, M: Display, C: Display>(
    source: &str,
    primary_span: &Spanned<T>,
    primary_message: M,
    context_span: &Spanned<U>,
    context_message: C,
) -> Report
Expand description

Create a [miette::Report] pointing at a primary span with additional context from a secondary span.

Useful for errors involving two locations, such as an alias error that points to both the alias usage and the original anchor definition.

ยงExamples

#[derive(serde::Deserialize)]
struct Cfg {
    anchor: Spanned<String>,
    alias: Spanned<String>,
}
let yaml = "anchor: &a 1\nalias: *a";
let cfg: Cfg = from_str(yaml).unwrap();

let report = spanned_error_with_context(
    yaml,
    &cfg.alias,
    "circular reference",
    &cfg.anchor,
    "defined here",
);