flow_graph_interpreter/graph/
error.rs

1use flow_expression_parser::ast::InstanceTarget;
2use flow_graph::NodePort;
3
4#[derive(thiserror::Error, Debug, Clone, PartialEq)]
5#[non_exhaustive]
6pub enum Error {
7  #[error(transparent)]
8  CoreError(#[from] flow_graph::error::Error),
9  #[error("Missing downstream '{0}'")]
10  MissingDownstream(String),
11  #[error("Could not find node named '{0}'")]
12  NodeNotFound(String),
13  #[error("Could not infer what downstream port '{from}->{to }' should connect to, known ports are {}", .known_ports.join(", "))]
14  PortInferenceDown {
15    from: String,
16    to: InstanceTarget,
17    known_ports: Vec<String>,
18  },
19  #[error("Could not infer what upstream port '{from }->{to}' should connect to, known ports are {}", .known_ports.join(", "))]
20  PortInferenceUp {
21    to: String,
22    from: InstanceTarget,
23    known_ports: Vec<String>,
24  },
25  #[error("Could not find signature for operation '{operation}' on component '{component}', available operations are: {}", .available.join(", "))]
26  MissingOperation {
27    component: String,
28    operation: String,
29    available: Vec<String>,
30  },
31  #[error("Could not render operation config for '{0}': {1}")]
32  Config(String, String),
33  #[error("Invalid config for core operation '{0}': {1}")]
34  CoreOperation(String, String),
35}
36
37impl Error {
38  pub(crate) fn missing_downstream<T: Into<String>>(port: T) -> Self {
39    Error::MissingDownstream(port.into())
40  }
41  pub(crate) fn node_not_found(node: impl std::fmt::Display) -> Self {
42    Error::NodeNotFound(node.to_string())
43  }
44  pub(crate) fn port_inference_down<T: std::fmt::Display>(
45    from: &InstanceTarget,
46    from_port: T,
47    to: InstanceTarget,
48    known_ports: &[NodePort],
49  ) -> Self {
50    Error::PortInferenceDown {
51      from: format!("{}.{}", from, from_port),
52      to,
53      known_ports: known_ports.iter().map(|p| p.name().to_owned()).collect(),
54    }
55  }
56  pub(crate) fn port_inference_up<T: std::fmt::Display>(
57    to: &InstanceTarget,
58    to_port: T,
59    from: InstanceTarget,
60    known_ports: &[NodePort],
61  ) -> Self {
62    Error::PortInferenceUp {
63      to: format!("{}.{}", to, to_port),
64      from,
65      known_ports: known_ports.iter().map(|p| p.name().to_owned()).collect(),
66    }
67  }
68
69  pub(crate) fn missing_operation<T: Into<String>, J: Into<String>>(
70    component: T,
71    operation: J,
72    available: &[&str],
73  ) -> Self {
74    Error::MissingOperation {
75      component: component.into(),
76      operation: operation.into(),
77      available: available.iter().map(|s| (*s).to_owned()).collect(),
78    }
79  }
80
81  pub(crate) fn config<T: Into<String>, J: Into<String>>(id: T, err: J) -> Self {
82    Error::Config(id.into(), err.into())
83  }
84  pub(crate) fn core_operation<T: Into<String>, J: Into<String>>(id: T, err: J) -> Self {
85    Error::CoreOperation(id.into(), err.into())
86  }
87}