summaryrefslogtreecommitdiffstats
path: root/src/backends/run_error.rs
blob: 0681ea8b6c772ff0a48988295b6b5693edf0515a (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
use crate::wait::WaitError;
use std::io::Error as IoError;

#[derive(Debug)]
pub enum RunError {
    IoError(std::io::Error),
    WaitError(WaitError),
}

impl From<IoError> for RunError {
    fn from(err: IoError) -> Self {
        RunError::IoError(err)
    }
}

impl From<WaitError> for RunError {
    fn from(err: WaitError) -> Self {
        RunError::WaitError(err)
    }
}

impl std::fmt::Display for RunError {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match &*self {
            RunError::IoError(e) => write!(f, "I/O error: {}", e),
            RunError::WaitError(e) => write!(f, "Wait error: {}", e),
        }
    }
}

impl std::error::Error for RunError {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match *self {
            RunError::IoError(ref e) => Some(e),
            RunError::WaitError(ref e) => Some(e),
        }
    }
}