Diagnostic

Struct Diagnostic 

Source
pub struct Diagnostic {
    pub severity: Severity,
    pub code: Option<String>,
    pub message: String,
    pub primary: Option<Location>,
    pub hint: Option<String>,
    pub source: Option<Box<dyn Error + Send + Sync>>,
}
Expand description

Structured diagnostic information

Fields§

§severity: Severity

Error severity level

§code: Option<String>

Optional error code (e.g., “E001”, “typst::syntax”)

§message: String

Human-readable error message

§primary: Option<Location>

Primary source location

§hint: Option<String>

Optional hint for fixing the error

§source: Option<Box<dyn Error + Send + Sync>>

Source error that caused this diagnostic (for error chaining) Note: This field is excluded from serialization as Error trait objects cannot be serialized

Implementations§

Source§

impl Diagnostic

Source

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

Create a new diagnostic

Source

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

Set the error code

Source

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

Set the primary location

Source

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

Set a hint

Source

pub fn with_source(self, source: Box<dyn Error + Send + Sync>) -> Self

Set error source (chainable)

Source

pub fn source_chain(&self) -> Vec<String>

Get the source chain as a list of error messages

Source

pub fn fmt_pretty(&self) -> String

Format diagnostic for pretty printing

Source

pub fn fmt_pretty_with_source(&self) -> String

Format diagnostic with source chain for debugging

Trait Implementations§

Source§

impl Debug for Diagnostic

Source§

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

Formats the value using the given formatter. 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 From<&Diagnostic> for SerializableDiagnostic

Source§

fn from(diag: &Diagnostic) -> Self

Converts to this type from the input type.
Source§

impl From<Diagnostic> for SerializableDiagnostic

Source§

fn from(diag: Diagnostic) -> Self

Converts to this type from the input type.
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

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.
Source§

impl<T> DynFilter for T
where T: Send + Sync + 'static,

Source§

impl<T> ErasedDestructor for T
where T: 'static,