aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/src/asset/chain/error.rs
blob: 5221e572051c4d769b0e10f9ee8394195011233f (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
use crate::error::{ProgramExecuteError, ProgramInternalExecuteError};

#[derive(thiserror::Error, Debug)]
pub enum ChainProcessError {
    #[error("Other error: {0}")]
    Other(String),

    #[error("IO error: {0}")]
    IO(#[from] std::io::Error),
}

impl From<ProgramExecuteError> for ChainProcessError {
    fn from(value: ProgramExecuteError) -> Self {
        match value {
            ProgramExecuteError::DispatcherNotFound => {
                ChainProcessError::Other("DispatcherNotFound".into())
            }
            ProgramExecuteError::RendererNotFound(r) => {
                ChainProcessError::Other(format!("RendererNotFound: {}", r))
            }
            ProgramExecuteError::Other(e) => ChainProcessError::Other(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))
            }
        }
    }
}