yolk/
multi_error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#[derive(Debug, thiserror::Error, miette::Diagnostic)]
#[error("{message}")]
#[diagnostic()]
pub struct MultiError {
    message: String,
    #[related]
    errors: Vec<miette::Report>,
}

impl MultiError {
    pub fn new(message: impl Into<String>, errors: Vec<miette::Report>) -> Self {
        Self {
            message: message.into(),
            errors,
        }
    }
}
impl From<miette::Report> for MultiError {
    fn from(report: miette::Report) -> Self {
        Self {
            message: "Something went wrong".to_string(),
            errors: vec![report],
        }
    }
}