report

Macro report 

Source
macro_rules! report {
    ($err:expr $(,)?) => { ... };
}
๐Ÿ‘ŽDeprecated since 0.6.0: use IntoReport::into_report instead
Expand description

Creates a Report from the given parameters.

The parameters may either be Error or a Report. The returned Report will use the the provided type as context.

ยงExamples

Create a Report from Error:

use std::fs;

use error_stack::report;

match fs::read_to_string("/path/to/file") {
    Ok(content) => println!("file contents: {content}"),
    Err(err) => return Err(report!(err)),
}
use core::error::Error;
use core::fmt;

use error_stack::report;

#[derive(Debug)]
struct PermissionDenied(User, Resource);

impl fmt::Display for PermissionDenied {
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
        ...
}

impl Error for PermissionDenied {}

if !has_permission(&user, &resource) {
    return Err(report!(PermissionDenied(user, resource)));
}