use std::io;
use std::path::PathBuf;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("IO error: {0}")]
Io(#[from] io::Error),
#[error("Failed to read config file '{path}': {source}")]
ConfigRead { path: PathBuf, source: io::Error },
#[error("Failed to parse config: {0}")]
ConfigParse(#[from] toml::de::Error),
#[error("Config validation failed: {0}")]
ConfigValidation(String),
#[error("Unknown dependency '{0}' - jail not defined")]
UnknownDependency(String),
#[error("Jail '{0}' not found")]
JailNotFound(String),
#[error("Jail '{0}' is already running")]
JailAlreadyRunning(String),
#[error("Jail '{0}' is not running")]
JailNotRunning(String),
#[error("Jail '{0}' already exists")]
JailExists(String),
#[error("Jail creation failed: {0}")]
JailCreationFailed(String),
#[error("Jail path does not exist: {0}")]
JailPathNotFound(PathBuf),
#[error("Jail operation failed: {0}")]
JailOperation(String),
#[error("jail_get syscall failed: {0}")]
JailGet(String),
#[error("jail_set syscall failed: {0}")]
JailSet(String),
#[error("jail_remove syscall failed")]
JailRemoveFailed,
#[error("Failed to attach to jail with JID {0}")]
JailAttachFailed(i32),
#[error("Command execution failed in jail: {0}")]
JailExecFailed(String),
#[error("Failed to create C string: {0}")]
CString(#[from] std::ffi::NulError),
#[error("ZFS operation failed: {0}")]
Zfs(String),
#[error("ZFS not enabled but required for operation")]
ZfsNotEnabled,
#[error("Failed to download: {0}")]
DownloadFailed(String),
#[error("Checksum mismatch for {file}: expected {expected}, got {actual}")]
ChecksumMismatch {
file: String,
expected: String,
actual: String,
},
#[error("Release '{0}' not found")]
ReleaseNotFound(String),
#[error("Release '{0}' already exists")]
ReleaseAlreadyExists(String),
#[error("Failed to extract archive: {0}")]
ExtractionFailed(String),
#[error("Unsupported architecture: {0}")]
UnsupportedArch(String),
#[error("Feature '{feature}' requires FreeBSD {minimum}+, but running {current}")]
UnsupportedOsVersion {
feature: String,
minimum: String,
current: String,
},
#[error("Invalid version format: {0}")]
InvalidVersion(String),
#[error("Command '{command}' failed: {message}")]
CommandFailed { command: String, message: String },
#[error("Network error: {0}")]
Network(String),
#[error("Interface '{0}' not found")]
InterfaceNotFound(String),
#[error("Bridge '{0}' already exists")]
BridgeAlreadyExists(String),
#[error("Hook failed at phase '{phase}': {command} - {message}")]
HookFailed {
phase: String,
command: String,
message: String,
},
#[error("Hook timeout after {0} seconds")]
HookTimeout(u64),
#[error("Jail command timeout after {0} seconds")]
JailTimeout(u64),
#[error("Health check failed for jail '{jail}' ({check}): {message}")]
HealthCheckFailed {
jail: String,
check: String,
message: String,
},
#[error("Template parse failed: {0}")]
TemplateParseFailed(String),
#[error("Build failed at step '{step}': {message}")]
BuildFailed { step: String, message: String },
#[error("Copy failed: {0}")]
CopyFailed(String),
#[error("Invalid argument: {0}")]
InvalidArgument(String),
}
pub type Result<T> = std::result::Result<T, Error>;