Skip to main content

holochain/conductor/manager/
error.rs

1#![allow(missing_docs)]
2
3use crate::conductor::error::ConductorError;
4use thiserror::Error;
5
6/// An error that is thrown from within the Task Manager itself.
7/// An unrecoverable ManagedTaskError can be bubbled up into a TaskManagerError.
8#[derive(Error, Debug)]
9pub enum TaskManagerError {
10    #[error("Conductor has exited due to an unrecoverable error in a managed task {0}")]
11    Unrecoverable(Box<ManagedTaskError>),
12
13    #[error(transparent)]
14    Join(#[from] tokio::task::JoinError),
15
16    #[error("Task manager encountered an internal error: {0}")]
17    Internal(Box<dyn std::error::Error + Send + Sync>),
18}
19
20impl TaskManagerError {
21    pub fn internal<E>(err: E) -> Self
22    where
23        E: std::error::Error + Send + Sync + 'static,
24    {
25        Self::Internal(Box::new(err))
26    }
27}
28
29pub type TaskManagerResult = Result<(), TaskManagerError>;
30
31/// An error that is thrown from within a managed task
32#[derive(Error, Debug)]
33pub enum ManagedTaskError {
34    #[error(transparent)]
35    Conductor(#[from] Box<ConductorError>),
36
37    #[error(transparent)]
38    Io(#[from] std::io::Error),
39
40    #[error(transparent)]
41    Join(#[from] tokio::task::JoinError),
42
43    #[error(transparent)]
44    Recv(#[from] tokio::sync::broadcast::error::RecvError),
45}
46
47pub type ManagedTaskResult = Result<(), ManagedTaskError>;
48
49impl ManagedTaskError {
50    pub fn is_recoverable(&self) -> bool {
51        use ConductorError as C;
52        use ManagedTaskError::*;
53        #[allow(clippy::match_like_matches_macro)]
54        match self {
55            Io(_) | Join(_) | Recv(_) => false,
56            Conductor(err) => match **err {
57                C::ShuttingDown => true,
58                // TODO: identify all recoverable cases
59                _ => false,
60            },
61        }
62    }
63}