use std::convert::Infallible;
use crate::Errno;
use crate::executor::{InstallError, drive, session};
use crate::topology::lending;
#[derive(Debug)]
pub enum Error<T, E = Infallible> {
Drive(drive::Error),
Quiesce {
output: T,
drive: drive::Error,
disarm: Option<Errno>,
},
Install {
cause: InstallError<E>,
disarm: Option<Errno>,
},
}
impl<T, E> Error<T, E> {
pub fn output(&self) -> Option<&T> {
match self {
Self::Quiesce { output, .. } => Some(output),
Self::Drive(_) | Self::Install { .. } => None,
}
}
pub fn cause(&self) -> session::Cause<'_, E> {
match self {
Self::Drive(error) => session::Cause::Drive(error),
Self::Quiesce { drive, disarm, .. } => session::Cause::Quiesce {
drive,
disarm: *disarm,
},
Self::Install { cause, disarm } => session::Cause::Install {
cause,
disarm: *disarm,
},
}
}
}
impl<T, E> From<drive::Error> for Error<T, E> {
fn from(error: drive::Error) -> Self {
Self::Drive(error)
}
}
impl<T, X> From<lending::Error<Infallible, T, X>> for Error<T, X> {
fn from(error: lending::Error<Infallible, T, X>) -> Self {
match error {
lending::Error::Run(error) => error,
lending::Error::Build(never) => match never {},
}
}
}