mago_source/
error.rs

1use crate::SourceIdentifier;
2
3#[derive(Debug)]
4pub enum SourceError {
5    UnavailableSource(SourceIdentifier),
6    IOError(std::io::Error),
7}
8
9impl std::fmt::Display for SourceError {
10    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11        match self {
12            Self::UnavailableSource(source_identifier) => write!(f, "source is not available: {source_identifier:?}"),
13            Self::IOError(error) => write!(f, "error loading source: {error}"),
14        }
15    }
16}
17
18impl std::error::Error for SourceError {
19    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
20        match self {
21            Self::UnavailableSource(_) => None,
22            Self::IOError(error) => Some(error),
23        }
24    }
25}
26
27impl From<std::io::Error> for SourceError {
28    fn from(error: std::io::Error) -> Self {
29        Self::IOError(error)
30    }
31}