]> git.lizzy.rs Git - rust.git/blob - src/tools/jsondocck/src/error.rs
Auto merge of #97870 - eggyal:inplace_fold_spec, r=wesleywiser
[rust.git] / src / tools / jsondocck / src / error.rs
1 use crate::Command;
2 use std::error::Error;
3 use std::fmt;
4
5 #[derive(Debug)]
6 pub enum CkError {
7     /// A check failed. File didn't exist or failed to match the command
8     FailedCheck(String, Command),
9     /// An error triggered by some other error
10     Induced(Box<dyn Error>),
11 }
12
13 impl fmt::Display for CkError {
14     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15         match self {
16             CkError::FailedCheck(msg, cmd) => {
17                 write!(f, "Failed check: {} on line {}", msg, cmd.lineno)
18             }
19             CkError::Induced(err) => write!(f, "Check failed: {}", err),
20         }
21     }
22 }
23
24 impl<T: Error + 'static> From<T> for CkError {
25     fn from(err: T) -> CkError {
26         CkError::Induced(Box::new(err))
27     }
28 }