quarto-error-reporting
Structured, source-aware diagnostics with a pluggable error-code catalog.
This crate produces compiler-quality diagnostics — a title, a problem statement,
detail bullets, hints, and an optional source span rendered with
ariadne — and lets the embedding product
decide how error codes map to titles and documentation URLs. It originated as
Quarto's diagnostics layer but carries no Quarto-specific data: the Q-*
catalog lives in a separate crate that installs itself at startup.
Core types
DiagnosticMessage— a diagnostic (kind, title, problem, details, hints, optional code and source location). Renders to ANSI text (to_text) or JSON.DiagnosticMessageBuilder— a tidyverse-style builder (.problem(),.add_detail(),.add_hint(),.with_code(),.with_location()).CatalogProvider— the seam an embedder implements to resolve a code toErrorCodeInfo(title, message template, docs URL, subsystem). Install one process-wide withinstall_catalog; with none installed, lookups returnNone(EmptyCatalog).
Example
use DiagnosticMessageBuilder;
let diag = error
.with_code
.problem
.add_hint
.build;
println!;
The pluggable catalog
Codes are just strings to this crate. To attach titles and docs URLs, implement
CatalogProvider and install it once at startup:
use ;
;
install_catalog;
let _ = get_docs_url; // resolved via the installed catalog
This is the host side of a cross-package error-code discipline: a library mints namespaced codes it owns; the product embedding it remaps those to its own user-facing codes and supplies the catalog. A consumer that installs nothing gets code-only diagnostics, which is a valid, leaner mode.
Features
json(off by default) — enables theJsonDiagnosticmachine-readable wire shape and itsschemars-generated JSON Schema. Leave it off if you only need the diagnostic/builder/text-render API; enable it for tooling that consumes diagnostics over a wire (editors, language servers, web UIs).
License
MIT © Posit Software, PBC