aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/src/asset/chain/error.rs
blob: 39e4f628334eb2aca4f891bc662c7c0044eae0e7 (plain) (blame)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use crate::error::ProgramInternalExecuteError;

#[derive(Debug)]
pub enum ChainProcessError {
    Other(String),
    IO(std::io::Error),
}

impl std::fmt::Display for ChainProcessError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            ChainProcessError::Other(s) => write!(f, "Other error: {}", s),
            ChainProcessError::IO(e) => write!(f, "IO error: {}", e),
        }
    }
}

impl std::error::Error for ChainProcessError {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            ChainProcessError::IO(e) => Some(e),
            ChainProcessError::Other(_) => None,
        }
    }
}

impl From<std::io::Error> for ChainProcessError {
    fn from(e: std::io::Error) -> Self {
        ChainProcessError::IO(e)
    }
}

impl From<ProgramInternalExecuteError> for ChainProcessError {
    fn from(value: ProgramInternalExecuteError) -> Self {
        match value {
            ProgramInternalExecuteError::DispatcherNotFound => {
                ChainProcessError::Other("DispatcherNotFound".into())
            }
            ProgramInternalExecuteError::RendererNotFound(r) => {
                ChainProcessError::Other(format!("RendererNotFound: {}", r))
            }
            ProgramInternalExecuteError::Other(e) => ChainProcessError::Other(e),
            ProgramInternalExecuteError::IO(e) => {
                ChainProcessError::Other(format!("IOError: {:?}", e))
            }
        }
    }
}