Skip to main content

dope_runtime/executor/drive/
error.rs

1use std::{mem, time};
2
3use dope_core::{
4    Errno,
5    driver::{life, result::poll, schedule::ready},
6};
7use drive::{clock, regress::Regression};
8use poll::fault;
9
10use crate::executor::drive;
11
12/// Failure while driving one executor application.
13
14#[derive(Debug)]
15pub enum Error {
16    Boot(life::Busy),
17    Capacity(ready::Capacity),
18    Poll(poll::Error),
19    Completion(fault::Dispatch),
20    Deadline(clock::Range),
21    ClockMovedBackwards(Regression),
22    TimerDisarm(Errno),
23    Shutdown,
24    QuiescenceTimeout,
25    Timeout,
26}
27
28impl Error {
29    pub(crate) const fn timeout(clock::Elapsed: clock::Elapsed) -> Self {
30        Self::Timeout
31    }
32
33    pub(crate) const fn quiesce(clock::Elapsed: clock::Elapsed) -> Self {
34        Self::QuiescenceTimeout
35    }
36
37    #[must_use]
38    pub const fn kind(&self) -> drive::Kind<'_> {
39        match self {
40            Self::Boot(error) => drive::Kind::Boot(error),
41            Self::Capacity(error) => drive::Kind::Capacity(error),
42            Self::Poll(error) => drive::Kind::Poll(error),
43            Self::Completion(fault) => drive::Kind::Completion(fault),
44            Self::Deadline(range) => drive::Kind::Deadline(range),
45            Self::ClockMovedBackwards(error) => drive::Kind::ClockMovedBackwards(error),
46            Self::TimerDisarm(error) => drive::Kind::TimerDisarm(error),
47            Self::Shutdown => drive::Kind::Shutdown,
48            Self::QuiescenceTimeout => drive::Kind::QuiescenceTimeout,
49            Self::Timeout => drive::Kind::Timeout,
50        }
51    }
52}
53
54impl Error {
55    pub(crate) const fn regression(ask: time::Instant, current: time::Instant) -> Self {
56        Self::ClockMovedBackwards(Regression::new(ask, current))
57    }
58}
59
60impl From<life::Busy> for Error {
61    fn from(error: life::Busy) -> Self {
62        Self::Boot(error)
63    }
64}
65
66impl From<ready::Capacity> for Error {
67    fn from(error: ready::Capacity) -> Self {
68        Self::Capacity(error)
69    }
70}
71
72impl From<poll::Error> for Error {
73    fn from(error: poll::Error) -> Self {
74        Self::Poll(error)
75    }
76}
77
78impl From<fault::Dispatch> for Error {
79    fn from(failure: fault::Dispatch) -> Self {
80        Self::Completion(failure)
81    }
82}
83
84impl From<clock::Range> for Error {
85    fn from(range: clock::Range) -> Self {
86        Self::Deadline(range)
87    }
88}
89
90const _: () = {
91    assert!(!mem::needs_drop::<Error>());
92    assert!(
93        mem::size_of::<Error>() <= mem::size_of::<fault::Dispatch>() + mem::align_of::<Error>()
94    );
95};