1use thiserror::Error;
4
5#[derive(Error, Debug)]
7pub enum SimError {
8 #[error("Configuration error: {0}")]
10 Config(String),
11
12 #[error("Validation error: {0}")]
14 Validation(String),
15
16 #[error("Entity not found: {entity_type} with id {id}")]
18 NotFound { entity_type: &'static str, id: u32 },
19
20 #[error("Invalid state transition: {0}")]
22 InvalidState(String),
23
24 #[error("Capacity exceeded: {0}")]
26 CapacityExceeded(String),
27
28 #[error("Inventory error: {0}")]
30 Inventory(String),
31
32 #[error("Routing error: no path from {from} to {to}")]
34 NoPath { from: u32, to: u32 },
35
36 #[error("IO error: {0}")]
38 Io(#[from] std::io::Error),
39
40 #[error("Serialization error: {0}")]
42 Serialization(String),
43}
44
45impl SimError {
46 pub fn robot_not_found(id: u32) -> Self {
48 Self::NotFound {
49 entity_type: "Robot",
50 id,
51 }
52 }
53
54 pub fn node_not_found(id: u32) -> Self {
56 Self::NotFound {
57 entity_type: "Node",
58 id,
59 }
60 }
61
62 pub fn edge_not_found(id: u32) -> Self {
64 Self::NotFound {
65 entity_type: "Edge",
66 id,
67 }
68 }
69
70 pub fn station_not_found(id: u32) -> Self {
72 Self::NotFound {
73 entity_type: "Station",
74 id,
75 }
76 }
77
78 pub fn task_not_found(id: u32) -> Self {
80 Self::NotFound {
81 entity_type: "Task",
82 id,
83 }
84 }
85
86 pub fn order_not_found(id: u32) -> Self {
88 Self::NotFound {
89 entity_type: "Order",
90 id,
91 }
92 }
93
94 pub fn sku_not_found(id: u32) -> Self {
96 Self::NotFound {
97 entity_type: "SKU",
98 id,
99 }
100 }
101}
102
103pub type SimResult<T> = Result<T, SimError>;