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 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§
§severity: SeverityError severity level
code: Option<String>Optional error code (e.g., “E001”, “typst::syntax”)
message: StringHuman-readable error message
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>Optional hint for fixing the error
source_chain: Vec<String>Flattened cause chain (outermost first).
Implementations§
Source§impl Diagnostic
impl Diagnostic
Sourcepub fn with_location(self, location: Location) -> Self
pub fn with_location(self, location: Location) -> Self
Set the primary location
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.
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.
Sourcepub fn fmt_pretty(&self) -> String
pub fn fmt_pretty(&self) -> String
Format diagnostic for pretty printing
Sourcepub fn fmt_pretty_with_source(&self) -> String
pub fn fmt_pretty_with_source(&self) -> String
Format diagnostic with source chain for debugging
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 moreSource§impl Debug for Diagnostic
impl Debug for Diagnostic
Source§impl<'de> Deserialize<'de> for Diagnostic
impl<'de> Deserialize<'de> for Diagnostic
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for Diagnostic
impl Display for Diagnostic
Source§impl PartialEq for Diagnostic
impl PartialEq for Diagnostic
Source§fn eq(&self, other: &Diagnostic) -> bool
fn eq(&self, other: &Diagnostic) -> bool
self and other values to be equal, and is used by ==.