use thiserror::Error;
#[derive(Error, Debug)]
pub enum AnsibleError {
#[error("I/O operation failed: {0}")]
Io(#[from] std::io::Error),
#[error("Ansible command execution failed: {message}")]
CommandFailed {
message: String,
exit_code: Option<i32>,
stdout: Option<String>,
stderr: Option<String>,
},
#[error("Invalid module configuration: {0}")]
InvalidModule(String),
#[error("Invalid inventory configuration: {0}")]
InvalidInventory(String),
#[error("Playbook error: {0}")]
PlaybookError(String),
#[error("Environment variable error: {0}")]
EnvironmentError(String),
#[error("Configuration error: {0}")]
ConfigError(String),
#[error("Unsupported platform: {0}")]
UnsupportedPlatform(String),
#[error("Command not found: {0}")]
CommandNotFound(String),
#[error("System requirement not met: {0}")]
SystemRequirement(String),
#[error("Unknown error occurred")]
Unknown,
}
impl AnsibleError {
pub fn command_failed(
message: impl Into<String>,
exit_code: Option<i32>,
stdout: Option<String>,
stderr: Option<String>,
) -> Self {
Self::CommandFailed {
message: message.into(),
exit_code,
stdout,
stderr,
}
}
pub fn invalid_module(message: impl Into<String>) -> Self {
Self::InvalidModule(message.into())
}
pub fn invalid_inventory(message: impl Into<String>) -> Self {
Self::InvalidInventory(message.into())
}
pub fn playbook_error(message: impl Into<String>) -> Self {
Self::PlaybookError(message.into())
}
pub fn environment_error(message: impl Into<String>) -> Self {
Self::EnvironmentError(message.into())
}
pub fn config_error(message: impl Into<String>) -> Self {
Self::ConfigError(message.into())
}
pub fn unsupported_platform(message: impl Into<String>) -> Self {
Self::UnsupportedPlatform(message.into())
}
pub fn command_not_found(message: impl Into<String>) -> Self {
Self::CommandNotFound(message.into())
}
pub fn system_requirement(message: impl Into<String>) -> Self {
Self::SystemRequirement(message.into())
}
pub fn parsing_failed(message: impl Into<String>) -> Self {
Self::ConfigError(message.into())
}
pub fn io_error(message: impl Into<String>) -> Self {
Self::ConfigError(message.into())
}
}
pub type Result<T> = std::result::Result<T, AnsibleError>;