deep_causality/errors/
model_validation_error.rs1use crate::{CausaloidId, ContextId, ContextoidId};
7use std::error::Error;
8use std::fmt;
9
10#[derive(Debug, Clone, Hash, Eq, PartialEq)]
11pub enum ModelValidationError {
12 MissingCreateCausaloid,
14 DuplicateCausaloidID { id: CausaloidId },
15 TargetCausaloidNotFound { id: CausaloidId },
16
17 BaseContextNotFound,
19 DuplicateContextId { id: ContextId },
20 TargetContextNotFound { id: ContextId },
21 DuplicateExtraContextId { id: u64 },
22
23 TargetContextoidNotFound { id: ContextoidId },
25 DuplicateContextoidId { id: ContextoidId },
26 AddContextoidError { err: String },
27
28 UnsupportedOperation { operation: String },
30 UpdateNodeError { err: String },
31 RemoveNodeError { err: String },
32 InterpreterError { reason: String },
33}
34
35impl Error for ModelValidationError {}
36
37impl fmt::Display for ModelValidationError {
38 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
39 match self {
40 ModelValidationError::MissingCreateCausaloid => {
41 write!(
42 f,
43 "The generative output is missing the mandatory Causaloid creation command."
44 )
45 }
46 ModelValidationError::DuplicateCausaloidID { id } => {
47 write!(f, "Duplicate Causaloid ID found: {id}")
48 }
49 ModelValidationError::TargetCausaloidNotFound { id } => {
50 write!(f, "Target Causaloid with ID {id} not found")
51 }
52 ModelValidationError::BaseContextNotFound => {
53 write!(
54 f,
55 "Cannot perform operation because the base context has not been created"
56 )
57 }
58 ModelValidationError::DuplicateContextId { id } => {
59 write!(f, "Duplicate Context ID found: {id}")
60 }
61 ModelValidationError::TargetContextNotFound { id } => {
62 write!(f, "Target Context with ID {id} not found")
63 }
64 ModelValidationError::DuplicateExtraContextId { id } => {
65 write!(f, "Duplicate Extra Context ID found: {id}")
66 }
67
68 ModelValidationError::TargetContextoidNotFound { id } => {
69 write!(f, "Target Contextoid with ID {id} not found")
70 }
71
72 ModelValidationError::DuplicateContextoidId { id } => {
73 write!(f, "Duplicate Contextoid ID found: {id}")
74 }
75
76 ModelValidationError::UnsupportedOperation { operation } => {
77 write!(f, "Unsupported operation: {operation}")
78 }
79 ModelValidationError::UpdateNodeError { err } => {
80 write!(f, "Error updating node: {err}")
81 }
82 ModelValidationError::RemoveNodeError { err } => {
83 write!(f, "Error removing node: {err}")
84 }
85 ModelValidationError::InterpreterError { reason } => {
86 write!(f, "Interpreter error: {reason}")
87 }
88 ModelValidationError::AddContextoidError { err } => {
89 write!(f, "Error adding Contextoid: {err}")
90 }
91 }
92 }
93}