pub struct Error { /* private fields */ }
Expand description

Represents template errors.

If debug mode is enabled a template error contains additional debug information that can be displayed by formatting an error with the alternative formatting (format!("{:#}", err)). That information is also shown for the Debug display where the extended information is hidden when the alternative formatting is used.

Since MiniJinja takes advantage of chained errors it’s recommended to render the entire chain to better understand the causes.

Example

Here is an example of you might want to render errors:

match template.render(ctx) {
    Ok(result) => println!("{}", result),
    Err(err) => {
        eprintln!("Could not render template: {:#}", err);
        // render causes as well
        let mut err = &err as &dyn std::error::Error;
        while let Some(next_err) = err.source() {
            eprintln!();
            eprintln!("caused by: {:#}", next_err);
            err = next_err;
        }
    }
}

Implementations

Creates a new error with kind and detail.

Attaches another error as source to this error.

Returns the error kind

Returns the filename of the template that caused the error.

Returns the line number where the error ocurred.

Trait Implementations

Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
The lower-level source of this error, if any. Read more
👎Deprecated since 1.42.0: use the Display impl or to_string()
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type based access to context intended for error reports. Read more
Used when a Serialize implementation encounters any error while serializing a type. Read more
Converts to this type from the input type.
Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

🔬This is a nightly-only experimental API. (provide_any)
Data providers should implement this method to provide all values they are able to provide by using demand. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.