Skip to main content

ninja/common/
error.rs

1/// Error types specific to Shuriken operations.
2///
3/// Provides detailed error information for various failure scenarios
4/// when working with Shurikens and configuration.
5#[derive(Debug)]
6pub enum ShurikenError {
7    /// A requested Shuriken service was not found
8    ServiceNotFound(String),
9    /// Failed to spawn a process for a service
10    SpawnFailed(String, std::io::Error),
11    /// Could not retrieve the process ID
12    NoPid,
13    /// Configuration-related error
14    ConfigError(String),
15    /// The Shurikens directory does not exist
16    ShurikensDirectoryNotFound,
17    /// The provided service name is invalid
18    InvalidServiceName,
19    /// Failed to parse configuration from TOML
20    ConfigParseError(String, toml::de::Error),
21    /// I/O operation failed
22    IoError(std::io::Error),
23}
24
25impl std::fmt::Display for ShurikenError {
26    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27        match self {
28            ShurikenError::ServiceNotFound(name) => write!(f, "Service '{}' not found", name),
29            ShurikenError::SpawnFailed(name, err) => {
30                write!(f, "Failed to spawn service '{}': {}", name, err)
31            }
32            ShurikenError::NoPid => write!(f, "Could not get process ID"),
33            ShurikenError::ConfigError(msg) => write!(f, "Configuration error: {}", msg),
34            ShurikenError::ShurikensDirectoryNotFound => write!(f, "Shurikens directory not found"),
35            ShurikenError::InvalidServiceName => write!(f, "Invalid service name"),
36            ShurikenError::ConfigParseError(name, err) => {
37                write!(f, "Failed to parse config for '{}': {}", name, err)
38            }
39            ShurikenError::IoError(err) => write!(f, "IO error: {}", err),
40        }
41    }
42}
43
44impl std::error::Error for ShurikenError {}
45
46// Automatic error conversions
47impl From<std::io::Error> for ShurikenError {
48    fn from(err: std::io::Error) -> Self {
49        ShurikenError::IoError(err)
50    }
51}