brane_drv/
errors.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//  ERRORS.rs
//    by Lut99
//
//  Created:
//    01 Feb 2022, 16:13:53
//  Last edited:
//    08 Feb 2024, 16:49:47
//  Auto updated?
//    Yes
//
//  Description:
//!   Contains errors used within the brane-drv package only.
//

use std::error::Error;
use std::fmt::{Display, Formatter, Result as FResult};
use std::path::PathBuf;


/***** ERRORS *****/
/// Defines errors that relate to the RemoteVm.
#[derive(Debug)]
pub enum RemoteVmError {
    /// Failed to plan a workflow.
    PlanError { err: brane_tsk::errors::PlanError },
    /// Failed to run a workflow.
    ExecError { err: brane_exe::Error },

    /// The given node config was not for this type of node.
    IllegalNodeConfig { path: PathBuf, got: String },
    /// Failed to load the given infra file.
    InfraFileLoad { path: PathBuf, err: brane_cfg::info::YamlError },
    /// Failed to load the given node config file.
    NodeConfigLoad { path: PathBuf, err: brane_cfg::info::YamlError },
}

impl Display for RemoteVmError {
    fn fmt(&self, f: &mut Formatter<'_>) -> FResult {
        use RemoteVmError::*;
        match self {
            PlanError { .. } => write!(f, "Failed to plan workflow"),
            ExecError { .. } => write!(f, "Failed to execute workflow"),

            IllegalNodeConfig { path, got } => {
                write!(f, "Illegal node config kind in node config '{}'; expected Central, got {}", path.display(), got)
            },
            InfraFileLoad { path, .. } => write!(f, "Failed to load infra file '{}'", path.display()),
            NodeConfigLoad { path, .. } => write!(f, "Failed to load node config file '{}'", path.display()),
        }
    }
}

impl Error for RemoteVmError {
    fn source(&self) -> Option<&(dyn Error + 'static)> {
        use RemoteVmError::*;
        match self {
            PlanError { err } => Some(err),
            ExecError { err } => Some(err),

            IllegalNodeConfig { .. } => None,
            InfraFileLoad { err, .. } => Some(err),
            NodeConfigLoad { err, .. } => Some(err),
        }
    }
}