about summary refs log tree commit diff
path: root/src/tools/jsondocck/src/error.rs
blob: 53b9af2874b8a253ad12df2dc6ca98a48c297441 (plain)
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
26
27
28
use crate::Command;
use std::error::Error;
use std::fmt;

#[derive(Debug)]
pub enum CkError {
    /// A check failed. File didn't exist or failed to match the command
    FailedCheck(String, Command),
    /// An error triggered by some other error
    Induced(Box<dyn Error>),
}

impl fmt::Display for CkError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            CkError::FailedCheck(msg, cmd) => {
                write!(f, "Failed check: {} on line {}", msg, cmd.lineno)
            }
            CkError::Induced(err) => write!(f, "Check failed: {}", err),
        }
    }
}

impl<T: Error + 'static> From<T> for CkError {
    fn from(err: T) -> CkError {
        CkError::Induced(Box::new(err))
    }
}