flow_graph_interpreter/interpreter/program/validator/
error.rs

1#[derive(thiserror::Error, Debug, Clone, PartialEq, Eq)]
2#[non_exhaustive]
3pub enum ValidationError {
4  #[error("Unused sender: {0}")]
5  UnusedSender(String),
6
7  #[error("Network contains circular references: {:?}", .0)]
8  NetworkUnresolvable(Vec<String>),
9
10  #[error("Missing component with id '{0}'")]
11  MissingComponent(String),
12
13  #[error("Could not find component referenced by id '{0}'")]
14  ComponentIdNotFound(String),
15
16  #[error("Missing operation '{name}' on component '{component}'")]
17  MissingOperation { component: String, name: String },
18
19  #[error("Invalid port '{port}' on operation '{id}' ('{component}::{operation}')")]
20  InvalidPort {
21    port: String,
22    id: String,
23    component: String,
24    operation: String,
25  },
26
27  #[error("Input port '{port}' on operation '{id}' ('{component}::{operation}') not connected to anything")]
28  MissingConnection {
29    port: String,
30    id: String,
31    component: String,
32    operation: String,
33  },
34
35  #[error(
36    "Signature for operation '{id}' ('{component}::{operation}') describes port '{port}' but '{port}' not found in graph"
37  )]
38  MissingPort {
39    port: String,
40    id: String,
41    component: String,
42    operation: String,
43  },
44
45  #[error(
46    "Input '{port}' on operation '{id}' ('{component}::{operation}') is connected but does not exist on operation."
47  )]
48  UnknownInput {
49    port: String,
50    id: String,
51    component: String,
52    operation: String,
53  },
54
55  #[error(
56    "Output '{port}' on operation '{id}' ('{component}::{operation}') is connected but does not exist on operation."
57  )]
58  UnknownOutput {
59    port: String,
60    id: String,
61    component: String,
62    operation: String,
63  },
64
65  #[error("Unused output port '{port}' on operation '{id}' ('{component}::{operation}')")]
66  UnusedOutput {
67    port: String,
68    id: String,
69    component: String,
70    operation: String,
71  },
72}
73
74#[derive(thiserror::Error, Debug, Clone, PartialEq, Eq)]
75#[must_use]
76pub struct OperationInvalid {
77  errors: Vec<ValidationError>,
78  schematic: String,
79}
80
81impl OperationInvalid {
82  pub fn new(schematic: String, errors: Vec<ValidationError>) -> Self {
83    Self { schematic, errors }
84  }
85}
86
87impl std::fmt::Display for OperationInvalid {
88  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
89    write!(
90      f,
91      "Flow '{}' could not be validated: {}",
92      self.schematic,
93      self.errors.iter().map(|e| e.to_string()).collect::<Vec<_>>().join(", ")
94    )
95  }
96}