#[non_exhaustive]pub struct Diagnostic {
pub severity: Severity,
pub code: Option<String>,
pub message: String,
pub location: Option<Location>,
pub path: Option<String>,
pub hint: Option<String>,
pub args: BTreeMap<String, Value>,
pub source_chain: Vec<String>,
}Expand description
Structured diagnostic information.
source_chain is a flat list of error messages from any attached
std::error::Error cause chain, eagerly walked at construction time so
the diagnostic remains trivially Clone and fully serializable across
every binding boundary.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.severity: Severity§code: Option<String>Optional error code (e.g., “E001”, “typst::syntax”)
message: String§location: Option<Location>Primary source location (text anchor: file/line/column).
Set by parsers and backend compilers. May co-exist with Self::path:
the two anchors are independent.
path: Option<String>Document-model anchor: a dotted/bracketed path into the typed
crate::document::Document.
Set by schema validation and coercion. See the module-level docs for
the path grammar and conventions. May co-exist with Self::location.
hint: Option<String>§args: BTreeMap<String, Value>The facts Self::message interpolates, keyed by name: with
Self::code, the substitution unit a consumer needs to word this
diagnostic in its own language.
One code carries one key set, tabulated per code in
prose/canon/ERROR.md § “Diagnostic args” and tested against it.
Values keep their JSON shape, so joining and pluralizing stay the
consumer’s locale decisions.
Empty either because the code is outside the structured surface or because its sentence needs no facts beyond the code; canon tells the two apart. Engine prose never rides under a key: a consumer’s sentence may be coarser than ours, never half-translated.
source_chain: Vec<String>Flattened cause chain (outermost first). Upstream English, and untranslatable for the same reason the prose it wraps is.
Implementations§
Source§impl Diagnostic
impl Diagnostic
pub fn new(severity: Severity, message: String) -> Self
pub fn with_code(self, code: String) -> Self
pub fn with_location(self, location: Location) -> Self
Sourcepub fn with_path(self, path: String) -> Self
pub fn with_path(self, path: String) -> Self
Set the document-model path anchor.
See the module-level docs for the path grammar and conventions.
pub fn with_hint(self, hint: String) -> Self
Sourcepub fn with_args(self, args: BTreeMap<String, Value>) -> Self
pub fn with_args(self, args: BTreeMap<String, Value>) -> Self
Attach the message’s substitution facts. See Self::args.
Sourcepub fn with_source(self, source: &(dyn Error + 'static)) -> Self
pub fn with_source(self, source: &(dyn Error + 'static)) -> Self
Attach an error cause chain, walked eagerly into source_chain.
pub fn fmt_pretty(&self) -> String
Trait Implementations§
Source§impl Clone for Diagnostic
impl Clone for Diagnostic
Source§fn clone(&self) -> Diagnostic
fn clone(&self) -> Diagnostic
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more