use crate::errors::{Diagnostic, OperationFailure};
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("data error: {0}")]
Data(Diagnostic),
#[error("render error: {0}")]
Render(Diagnostic),
#[error(transparent)]
Operation(Box<OperationFailure>),
#[error("operation cancelled")]
Cancelled,
}
impl Error {
pub(crate) fn with_prefix(self, prefix: &str) -> Self {
match self {
Self::Data(diagnostic) => Self::Data(diagnostic.with_prefix(prefix)),
Self::Render(diagnostic) => Self::Render(diagnostic.with_prefix(prefix)),
other => other,
}
}
pub fn diagnostic(&self) -> Option<&Diagnostic> {
match self {
Self::Data(diagnostic) | Self::Render(diagnostic) => Some(diagnostic),
Self::Operation(failure) => failure.cause().diagnostic(),
_ => None,
}
}
}
impl From<std::convert::Infallible> for Error {
fn from(value: std::convert::Infallible) -> Self {
match value {}
}
}
pub type Result<T> = std::result::Result<T, Error>;