pub fn format_adam_error(
e: &Error,
parsed: &ParsedSheet,
source: &str,
file_name: &str,
renderer: &Renderer,
) -> StringExpand description
Formats an Error as a rustc-style diagnostic when possible.
Error::MethodFailed wraps an anyhow::Error raised by a compiled method
body; when that error carries a SpanContext (attached automatically by
cel-parser’s span-diagnostics feature for built-in arithmetic ops) this
renders a full caret diagnostic against source using renderer — pass
Renderer::styled for a real terminal (ANSI colors) or Renderer::plain
for a context that can’t display them (a browser <pre> element, a log file) —
with file_name (e.g. "begin/examples/toy_example.adm2") shown in the
diagnostic header. Otherwise, e’s sites are resolved against parsed via
adam_lang::ParsedSheet::locate_error: zero resolved sites falls back to e’s
Display message; exactly one renders a single-caret diagnostic; two or more render
a multi-span backtrace (e.g. every relationship binding in a cycle), primary site
first.
- Complexity: O(n) in the length of
source, plus O(s) in the number ofe’s sites —ParsedSheet::locate_errorand, on the multi-span path,cel_parser::format_multi_spanboth re-scansourceto render the annotated snippet.