use std::fmt;
use std::path::PathBuf;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
Io {
context: String,
source: std::io::Error,
},
NotAResult {
path: PathBuf,
line: u64,
},
Internal(String),
}
impl Error {
pub(crate) fn io(context: impl Into<String>, source: std::io::Error) -> Self {
Self::Io {
context: context.into(),
source,
}
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Io { context, source } => write!(f, "{context}: {source}"),
Self::NotAResult { path, line } => write!(
f,
"line {line} of `{}` isn't a result line, so it can't be resumed; check the file is this runner's output",
path.display()
),
Self::Internal(message) => write!(f, "the runner failed: {message}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Io { source, .. } => Some(source),
_ => None,
}
}
}