firewheel_graph/graph/
error.rsuse std::error::Error;
use std::fmt;
use super::{
compiler::{Edge, EdgeID, InPortIdx, OutPortIdx},
NodeID,
};
#[derive(Debug, Clone)]
pub enum AddEdgeError {
SrcNodeNotFound(NodeID),
DstNodeNotFound(NodeID),
InPortOutOfRange {
node: NodeID,
port_idx: InPortIdx,
num_in_ports: u32,
},
OutPortOutOfRange {
node: NodeID,
port_idx: OutPortIdx,
num_out_ports: u32,
},
EdgeAlreadyExists,
InputPortAlreadyConnected(NodeID, InPortIdx),
CycleDetected,
}
impl Error for AddEdgeError {}
impl fmt::Display for AddEdgeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::SrcNodeNotFound(node_id) => {
write!(
f,
"Could not add edge: could not find source node with ID {:?}",
node_id
)
}
Self::DstNodeNotFound(node_id) => {
write!(
f,
"Could not add edge: could not find destination node with ID {:?}",
node_id
)
}
Self::InPortOutOfRange {
node,
port_idx,
num_in_ports,
} => {
write!(
f,
"Input port idx {:?} is out of range on node {:?} with {} input ports",
port_idx, node, num_in_ports,
)
}
Self::OutPortOutOfRange {
node,
port_idx,
num_out_ports,
} => {
write!(
f,
"Output port idx {:?} is out of range on node {:?} with {} output ports",
port_idx, node, num_out_ports,
)
}
Self::EdgeAlreadyExists => {
write!(f, "Could not add edge: edge already exists in the graph",)
}
Self::InputPortAlreadyConnected(node_id, port_id) => {
write!(
f,
"Could not add edge: input port with ID {:?} on node with ID {:?} is already connected",
port_id,
node_id,
)
}
Self::CycleDetected => {
write!(f, "Could not add edge: cycle was detected")
}
}
}
}
#[derive(Debug)]
pub enum CompileGraphError {
CycleDetected,
NodeOnEdgeNotFound(Edge, NodeID),
NodeIDNotUnique(NodeID),
EdgeIDNotUnique(EdgeID),
ManyToOneError(NodeID, InPortIdx),
NodeActivationFailed(NodeID, Box<dyn Error>),
MessageChannelFull,
}
impl Error for CompileGraphError {}
impl fmt::Display for CompileGraphError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::CycleDetected => {
write!(f, "Failed to compile audio graph: a cycle was detected")
}
Self::NodeOnEdgeNotFound(edge, node_id) => {
write!(f, "Failed to compile audio graph: input data contains an edge {:?} referring to a non-existing node {:?}", edge, node_id)
}
Self::NodeIDNotUnique(node_id) => {
write!(f, "Failed to compile audio graph: input data contains multiple nodes with the same ID {:?}", node_id)
}
Self::EdgeIDNotUnique(edge_id) => {
write!(f, "Failed to compile audio graph: input data contains multiple edges with the same ID {:?}", edge_id)
}
Self::ManyToOneError(node_id, port_id) => {
write!(f, "Failed to compile audio graph: input data contains multiple edges that go to the same input port with ID {:?} on node with id {:?}", port_id, node_id)
}
Self::NodeActivationFailed(node_id, e) => {
write!(
f,
"Failed to compile audio graph: Node with ID {:?} failed to activate: {}",
node_id, e
)
}
Self::MessageChannelFull => {
write!(f, "Failed to compile audio graph: Message channel is full")
}
}
}
}