cuenv_task_graph/
error.rs1use std::fmt;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Debug, Clone)]
10pub enum Error {
11 CycleDetected {
13 message: String,
15 },
16
17 MissingDependency {
19 task: String,
21 dependency: String,
23 },
24
25 MissingDependencies {
27 missing: Vec<(String, String)>,
29 },
30
31 TopologicalSortFailed {
33 reason: String,
35 },
36
37 DuplicateNodeName {
39 name: String,
41 existing_kind: String,
43 new_kind: String,
45 },
46}
47
48impl fmt::Display for Error {
49 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50 match self {
51 Self::CycleDetected { message } => {
52 write!(f, "Cycle detected in task graph: {message}")
53 }
54 Self::MissingDependency { task, dependency } => {
55 write!(f, "Task '{task}' depends on missing task '{dependency}'")
56 }
57 Self::MissingDependencies { missing } => {
58 let list = missing
59 .iter()
60 .map(|(task, dep)| format!("Task '{task}' depends on missing task '{dep}'"))
61 .collect::<Vec<_>>()
62 .join(", ");
63 write!(f, "Missing dependencies: {list}")
64 }
65 Self::TopologicalSortFailed { reason } => {
66 write!(f, "Failed to sort tasks topologically: {reason}")
67 }
68 Self::DuplicateNodeName {
69 name,
70 existing_kind,
71 new_kind,
72 } => {
73 write!(
74 f,
75 "Node name '{name}' is already used by a {existing_kind}; cannot add as {new_kind}"
76 )
77 }
78 }
79 }
80}
81
82impl std::error::Error for Error {}