Skip to main content

Diagnostic

Struct Diagnostic 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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

Source

pub fn new(severity: Severity, message: String) -> Self

Source

pub fn with_code(self, code: String) -> Self

Source

pub fn with_location(self, location: Location) -> Self

Source

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.

Source

pub fn with_hint(self, hint: String) -> Self

Source

pub fn with_args(self, args: BTreeMap<String, Value>) -> Self

Attach the message’s substitution facts. See Self::args.

Source

pub fn with_source(self, source: &(dyn Error + 'static)) -> Self

Attach an error cause chain, walked eagerly into source_chain.

Source

pub fn fmt_pretty(&self) -> String

Trait Implementations§

Source§

impl Clone for Diagnostic

Source§

fn clone(&self) -> Diagnostic

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Diagnostic

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Diagnostic

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Diagnostic

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Diagnostic

Source§

fn eq(&self, other: &Diagnostic) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Diagnostic

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Diagnostic

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.