qudag_dag/
error.rs

1use crate::consensus::ConsensusError;
2use crate::vertex::VertexError;
3use thiserror::Error;
4
5/// Errors that can occur during DAG operations
6#[derive(Error, Debug)]
7pub enum DagError {
8    /// Node already exists in the graph
9    #[error("Node {0} already exists")]
10    NodeExists(String),
11
12    /// Node not found in the graph
13    #[error("Node {0} not found")]
14    NodeNotFound(String),
15
16    /// Invalid edge - creates a cycle
17    #[error("Edge would create cycle between {from} and {to}")]
18    CycleDetected {
19        /// Source node of the cycle-creating edge
20        from: String,
21        /// Target node of the cycle-creating edge
22        to: String,
23    },
24
25    /// Parent node missing for edge
26    #[error("Parent node {0} missing for edge")]
27    MissingParent(String),
28
29    /// Child node missing for edge
30    #[error("Child node {0} missing for edge")]
31    MissingChild(String),
32
33    /// Invalid node state transition
34    #[error("Invalid state transition for node {0}")]
35    InvalidStateTransition(String),
36
37    /// Consensus error
38    #[error("Consensus error: {0}")]
39    ConsensusError(String),
40
41    /// Vertex error
42    #[error("Vertex error: {0}")]
43    VertexError(#[from] VertexError),
44}
45
46impl From<ConsensusError> for DagError {
47    fn from(err: ConsensusError) -> Self {
48        DagError::ConsensusError(err.to_string())
49    }
50}