Skip to main content

dope_runtime/executor/session/
error.rs

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