Skip to main content

waremax_core/
error.rs

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