Skip to main content

taskgraph/
error.rs

1//! Error module for taskgraph-rs.
2//! Fully compatible with `no_std`.
3
4use core::fmt;
5
6/// Main error type for taskgraph-rs.
7#[derive(Debug, PartialEq, Eq)]
8pub enum TaskError {
9    /// A cycle was detected in the graph.
10    CycleDetected,
11    /// The graph has reached its maximum capacity.
12    CapacityExceeded,
13    /// A task execution failed.
14    TaskExecutionFailed(&'static str),
15    /// A task execution timed out.
16    Timeout,
17    /// Internal state error.
18    InvalidState,
19    /// A task panicked during execution (std only).
20    Panic,
21    /// Serialization/Deserialization error (Serde feature).
22    PersistenceError,
23}
24
25impl fmt::Display for TaskError {
26    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27        match self {
28            Self::CycleDetected => write!(f, "Cycle detected in DAG"),
29            Self::CapacityExceeded => write!(f, "Graph capacity exceeded"),
30            Self::TaskExecutionFailed(reason) => write!(f, "Task execution failed: {}", reason),
31            Self::Timeout => write!(f, "Task timed out"),
32            Self::InvalidState => write!(f, "Invalid internal state"),
33            Self::Panic => write!(f, "Task panicked"),
34            Self::PersistenceError => write!(f, "Persistence error"),
35        }
36    }
37}
38
39#[cfg(feature = "std")]
40impl std::error::Error for TaskError {}
41
42/// Result type used throughout the library.
43pub type Result<T> = core::result::Result<T, TaskError>;