buildkit_frontend/
utils.rs

1use std::fmt;
2
3use failure::Error;
4
5#[derive(Clone, Debug)]
6pub struct OutputRef(pub(crate) String);
7
8pub struct ErrorWithCauses(pub Error, &'static str);
9
10impl ErrorWithCauses {
11    pub fn multi_line(error: Error) -> Self {
12        Self(error, "\n  caused by: ")
13    }
14
15    pub fn single_line(error: Error) -> Self {
16        Self(error, " => caused by: ")
17    }
18
19    pub fn into_inner(self) -> Error {
20        self.0
21    }
22}
23
24impl fmt::Display for ErrorWithCauses {
25    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
26        write!(f, "{}", self.0)?;
27
28        for cause in self.0.iter_causes() {
29            write!(f, "{}{}", self.1, cause)?;
30        }
31
32        Ok(())
33    }
34}