Skip to main content

dope_core/executor/session/
error.rs

1use std::convert::Infallible;
2
3use crate::Errno;
4
5use crate::executor::{InstallError, drive, session};
6use crate::topology::lending;
7
8/// Application output and the failure observed while releasing its session.
9#[derive(Debug)]
10pub enum Error<T, E = Infallible> {
11    Drive(drive::Error),
12    Quiesce {
13        output: T,
14        drive: drive::Error,
15        disarm: Option<Errno>,
16    },
17    Install {
18        cause: InstallError<E>,
19        disarm: Option<Errno>,
20    },
21}
22
23impl<T, E> Error<T, E> {
24    /// Borrows the application result retained through a later session failure.
25    pub fn output(&self) -> Option<&T> {
26        match self {
27            Self::Quiesce { output, .. } => Some(output),
28            Self::Drive(_) | Self::Install { .. } => None,
29        }
30    }
31
32    /// Borrows the failure without moving or formatting application output.
33    pub fn cause(&self) -> session::Cause<'_, E> {
34        match self {
35            Self::Drive(error) => session::Cause::Drive(error),
36            Self::Quiesce { drive, disarm, .. } => session::Cause::Quiesce {
37                drive,
38                disarm: *disarm,
39            },
40            Self::Install { cause, disarm } => session::Cause::Install {
41                cause,
42                disarm: *disarm,
43            },
44        }
45    }
46}
47
48impl<T, E> From<drive::Error> for Error<T, E> {
49    fn from(error: drive::Error) -> Self {
50        Self::Drive(error)
51    }
52}
53
54impl<T, X> From<lending::Error<Infallible, T, X>> for Error<T, X> {
55    fn from(error: lending::Error<Infallible, T, X>) -> Self {
56        match error {
57            lending::Error::Run(error) => error,
58            lending::Error::Build(never) => match never {},
59        }
60    }
61}