imlet/types/computation/
model_error.rs1#[derive(Debug)]
3pub enum ModelError {
4 CyclicDependency(String),
6 MissingTag(String),
8 DuplicateTag(String),
10 InputIndexOutOfRange {
12 component: String,
13 num_inputs: usize,
14 index: usize,
15 },
16 IncorrectInputCount {
18 component: String,
19 num_inputs: usize,
20 count: usize,
21 },
22 MissingInput {
24 component: String,
25 index: usize,
26 },
27 TagGenerationFailed(String),
28 MissingOutput(),
30 MissingConfig(),
32 MissingRequiredParam(String),
34 IncorrectDataSize(usize, usize),
36 NoDefaultOutput,
38 Custom(String),
40}
41
42impl std::fmt::Display for ModelError {
43 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44 match self {
45 ModelError::CyclicDependency(component) => {
46 write!(
47 f,
48 "Cyclic dependency detected for {component}. The component is depending on itself."
49 )
50 }
51 ModelError::MissingTag(tag) => {
52 write!(f, "Could not find component with tag {tag} in model.")
53 }
54 ModelError::DuplicateTag(tag) => {
55 write!(f, "Component with tag {tag} already present in model.")
56 }
57 ModelError::InputIndexOutOfRange {
58 component,
59 num_inputs,
60 index,
61 } => {
62 write!(f, "Input index out of bounds for component {component}. The recieved index ({index}) is larger than the input count for the component ({num_inputs})")
63 }
64 ModelError::IncorrectInputCount {
65 component,
66 num_inputs,
67 count,
68 } => {
69 write!(f, "Incorrect inputs for component {component}. The recieved number ({count}) is larger than the input count for the component ({num_inputs})")
70 }
71 ModelError::MissingInput { component, index } => {
72 write!(
73 f,
74 "Component {component} is missing an input at index {index}. The model cannot be computed."
75 )
76 }
77 ModelError::TagGenerationFailed(tag) => {
78 write!(f, "Failed to generate increment for tag {tag}.")
79 }
80 ModelError::MissingOutput() => {
81 write!(f, "Failed to generate output as no output node specified.")
82 }
83 ModelError::MissingConfig() => write!(
84 f,
85 "Failed to generate output as no config is specified for the model."
86 ),
87 ModelError::MissingRequiredParam(param) => {
88 write!(f, "Required parameter {param} is missing from the builder.")
89 }
90 ModelError::Custom(message) => write!(f, "{message}"),
91 ModelError::IncorrectDataSize(data_size, field_size) => {
92 write!(f, "The provided data buffer of size (size={data_size}) is not matching the point count of the field (n={field_size}).")
93 }
94 ModelError::NoDefaultOutput => {
95 write!(f, "The model has no default output set. Please set one or provide a specific component.")
96 }
97 }
98 }
99}
100
101impl std::error::Error for ModelError {}