firewheel_graph/
error.rs

1use core::error::Error;
2use firewheel_core::{channel_config::ChannelCount, node::NodeID};
3
4use crate::graph::{Edge, EdgeID, PortIdx};
5
6/// An error occurred while attempting to add an edge to the graph.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
8pub enum AddEdgeError {
9    /// The given source node was not found in the graph.
10    #[error("Could not add edge: could not find source node with ID {0:?}")]
11    SrcNodeNotFound(NodeID),
12    /// The given destination node was not found in the graph.
13    #[error("Could not add edge: could not find destination node with ID {0:?}")]
14    DstNodeNotFound(NodeID),
15    /// The given input port index is out of range.
16    #[error("Input port idx {port_idx:?} is out of range on node {node:?} with {num_in_ports:?} input ports")]
17    InPortOutOfRange {
18        node: NodeID,
19        port_idx: PortIdx,
20        num_in_ports: ChannelCount,
21    },
22    /// The given output port index is out of range.
23    #[error("Output port idx {port_idx:?} is out of range on node {node:?} with {num_out_ports:?} output ports")]
24    OutPortOutOfRange {
25        node: NodeID,
26        port_idx: PortIdx,
27        num_out_ports: ChannelCount,
28    },
29    /// This edge would have created a cycle in the graph.
30    #[error("Could not add edge: cycle was detected")]
31    CycleDetected,
32}
33
34/// An error occurred while attempting to compile the audio graph
35/// into a schedule.
36#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
37pub enum CompileGraphError {
38    /// A cycle was detected in the graph.
39    #[error("Failed to compile audio graph: a cycle was detected")]
40    CycleDetected,
41    /// The input data contained an edge referring to a non-existing node.
42    #[error("Failed to compile audio graph: input data contains an edge {0:?} referring to a non-existing node {1:?}")]
43    NodeOnEdgeNotFound(Edge, NodeID),
44    /// The input data contained multiple nodes with the same ID.
45    #[error(
46        "Failed to compile audio graph: input data contains multiple nodes with the same ID {0:?}"
47    )]
48    NodeIDNotUnique(NodeID),
49    /// The input data contained multiple edges with the same ID.
50    #[error(
51        "Failed to compile audio graph: input data contains multiple edges with the same ID {0:?}"
52    )]
53    EdgeIDNotUnique(EdgeID),
54}
55
56/// An error occurred while attempting to activate an audio stream in
57/// a [`FirewheelCtx`][crate::context::FirewheelCtx].
58#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
59pub enum StartStreamError<E: Error> {
60    /// An audio stream is already running in this context.
61    #[error("Audio stream is already running")]
62    AlreadyStarted,
63    /// The old audio stream has not finished stopping yet.
64    ///
65    /// Wait some time and then try starting again.
66    ///
67    /// Note, in rare cases where the audio thread crashes without cleanly
68    /// dropping its contents, this may never succeed. Consider adding a
69    /// timeout to avoid deadlocking.
70    #[error("Failed to start audio stream: The old audio stream has not finished stopping yet")]
71    OldStreamNotFinishedStopping,
72    /// The audio graph failed to compile.
73    #[error("Failed to start audio stream: Audio graph failed to compile: {0}")]
74    GraphCompileError(#[from] CompileGraphError),
75    /// A backend-specific error occured.
76    #[error("Failed to start audio stream: {0}")]
77    BackendError(E),
78}
79
80/// An error occured while updating a [`FirewheelCtx`][crate::context::FirewheelCtx].
81#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
82pub enum UpdateError<E: Error> {
83    /// The context to processor message channel is full.
84    #[error("The Firewheel context to processor message channel is full")]
85    MsgChannelFull,
86    /// The audio graph failed to compile.
87    #[error("The audio graph failed to compile: {0}")]
88    GraphCompileError(#[from] CompileGraphError),
89    /// The audio stream stopped unexpectedly. A new audio stream (even if it's a
90    /// dummy audio stream), should be started as soon as possible.
91    #[error("The audio stream stopped unexpectedly: {0}")]
92    StreamStoppedUnexpectedly(Option<E>),
93}
94
95/// An error while removing a node in [`FirewheelCtx`][crate::context::FirewheelCtx].
96#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
97pub enum RemoveNodeError {
98    /// Removing the graph in node is not allowed.
99    #[error("Removing the graph in node is not allowed")]
100    CannotRemoveGraphInNode,
101    /// Removing the graph out node is not allowed.
102    #[error("Removing the graph out node is not allowed")]
103    CannotRemoveGraphOutNode,
104}