openfair/
error.rs

1use crate::simulations::model::nodes::NodeNames;
2
3#[derive(Debug, thiserror::Error)]
4pub enum Error {
5    // Model Errors
6    #[error("Incorrect model set")]
7    IncorrectModelSet,
8    #[error("Incorrect model ref: {0}")]
9    IncorrectModelRef(String),
10    #[error("Reference to undefined model: {0}")]
11    UndefinedModelReference(String),
12    #[error("Incorrect model: {n:?}")]
13    IncorrectModel { n: NodeNames },
14    #[error("Invalid model: Node {n:?} has {c} children")]
15    InvalidModel { n: NodeNames, c: usize },
16    #[error("Invalid input field: {e}")]
17    InvalidInputField { e: String },
18    #[error("Unsupported Distribution Setting: {e:?}")]
19    UnsupportedDistributionSetting { e: serde_json::Value },
20    #[error("Multiplication of vectors with different sizes {v1} {v2}")]
21    DifferentSizeVectorsMultiplication { v1: usize, v2: usize },
22    #[error("Addition of vectors with different sizes {v1} {v2}")]
23    DifferentSizeVectorsAddition { v1: usize, v2: usize },
24    #[error("Vectors of different sizes {v1} {v2}")]
25    DifferentSizeVectors { v1: usize, v2: usize },
26    #[error("Simulation count not found")]
27    InvalidSimulationCount,
28    #[error("Currency not found")]
29    InvalidCurrency,
30    #[error("Required Arrays of Models")]
31    RequiredModelArrays,
32    #[error("Required Field 'name' is not present in Model input")]
33    NameFieldNotPresent,
34    #[error("Required Field 'settings' is not present in Model input")]
35    SettingsFieldNotPresent,
36    #[error("Required Field 'type' is not present in Model input")]
37    TypeFieldNotPresent,
38    #[error("'type=model' not `{0}`")]
39    InvalidTypeField(String),
40    #[error("Invalid name: {0}")]
41    InvalidNameField(String),
42
43    // Scenario Errors
44    #[error("Threats field not found")]
45    ThreatsFieldNotFound,
46    #[error("Threat not found in threats: `{0}`")]
47    ThreatNotFound(String),
48    #[error("Threat Id not found: `{0}`")]
49    InvalidThreatId(String),
50    #[error("Params field not found")]
51    ParamsFieldNotFound,
52    #[error("Expected Frequency field not found")]
53    ExpectedFrequencyFieldNotFound,
54    #[error("Expected Frequency should be a string for threat: {0}")]
55    InvalidExpectedFrequency(String),
56    #[error("Expected Frequency must contain `min`, `mean`, `max`")]
57    ExpectedFrequencyMinMeanMaxNotFound,
58    #[error("Capability field not found")]
59    CapabilityFieldNotFound,
60    #[error("Capability should be a string for threat: {0}")]
61    InvalidCapability(String),
62    #[error("Capability must contain `min`, `mean`, `max`")]
63    CapabilityMinMeanMaxNotFound,
64    #[error("Loss Magnitude field not found")]
65    LossMagnitudeFieldNotFound,
66    #[error("Loss Magnitude should be a string for threat: {0}")]
67    InvalidLossMagnitude(String),
68    #[error("Loss Magnitude must contain `min`, `mean`, `max`")]
69    LossMagnitudeMinMeanMaxNotFound,
70    #[error("Difficulty field not found")]
71    DifficultyFieldNotFound,
72    #[error("Difficulty should be a string for control: {0}")]
73    InvalidDifficulty(String),
74    #[error("Difficulty must contain `min`, `mean`, `max`")]
75    DifficultyMinMeanMaxNotFound,
76    #[error("Controls field not found")]
77    ControlsFieldNotFound,
78    #[error("Control Ids field not found")]
79    ControlIdsNotFound,
80    #[error("Control not found in controls: `{0}`")]
81    InvalidControl(String),
82    #[error("Invalid Control Id: `{0}`")]
83    InvalidControlId(String),
84    #[error("Scenarios field not found")]
85    ScenariosFieldNotFound,
86
87    // Charting errors
88    #[error("Invalid Control in Chart: {0}")]
89    InvalidChartControl(String),
90    #[error("Invalid Mean in Chart: {0}")]
91    InvalidChartMean(f64),
92    #[error("Simulation Result not found")]
93    SimulationResultNotFound,
94
95    // Input read errors
96    #[error("Input Json not valid/error")]
97    InvalidInput,
98    #[error("Scenario field not found")]
99    ScenarioNotFound,
100    #[error("Model field not found")]
101    ModelNotFound,
102
103    // Generic Errors
104    #[error("Serde json error")]
105    Json(#[from] serde_json::Error),
106    #[error("{0}")]
107    Io(#[from] std::io::Error),
108    #[error("{0}")]
109    Generic(String),
110    #[error("Unknown Error")]
111    Unknown,
112}