mago_source/
error.rs

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
use crate::SourceIdentifier;

#[derive(Debug)]
pub enum SourceError {
    UnavailableSource(SourceIdentifier),
    IOError(std::io::Error),
}

impl std::fmt::Display for SourceError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::UnavailableSource(source_identifier) => write!(f, "source is not available: {:?}", source_identifier),
            Self::IOError(error) => write!(f, "error loading source: {}", error),
        }
    }
}

impl std::error::Error for SourceError {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            Self::UnavailableSource(_) => None,
            Self::IOError(error) => Some(error),
        }
    }
}

impl From<std::io::Error> for SourceError {
    fn from(error: std::io::Error) -> Self {
        Self::IOError(error)
    }
}