use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CapabilityError {
PathEscape {
requested: String,
},
NotFound {
requested: String,
},
NotAFile {
requested: String,
},
NotADirectory {
requested: String,
},
TooLarge {
bytes: u64,
limit: u64,
},
InvalidUtf8 {
requested: String,
},
EmptyCommand,
CommandParseError {
detail: String,
},
InvalidInput {
detail: String,
},
SpawnFailed {
detail: String,
},
Io {
detail: String,
},
Serialize {
detail: String,
},
Unsupported {
detail: String,
},
}
impl fmt::Display for CapabilityError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::PathEscape { requested } => {
write!(f, "path escapes repository root (Gate L5): {requested}")
}
Self::NotFound { requested } => write!(f, "resolve '{requested}': not found"),
Self::NotAFile { requested } => write!(f, "not a file: {requested}"),
Self::NotADirectory { requested } => write!(f, "not a directory: {requested}"),
Self::TooLarge { bytes, limit } => {
write!(f, "file too large: {bytes} bytes (limit {limit})")
}
Self::InvalidUtf8 { requested } => write!(f, "not valid UTF-8: {requested}"),
Self::EmptyCommand => write!(f, "empty command"),
Self::CommandParseError { detail } => write!(f, "cannot parse command: {detail}"),
Self::InvalidInput { detail } => write!(f, "{detail}"),
Self::SpawnFailed { detail } => write!(f, "failed to spawn: {detail}"),
Self::Io { detail } => write!(f, "{detail}"),
Self::Serialize { detail } => write!(f, "serialize observation: {detail}"),
Self::Unsupported { detail } => write!(f, "{detail}"),
}
}
}
impl std::error::Error for CapabilityError {}
impl From<CapabilityError> for String {
fn from(error: CapabilityError) -> Self {
error.to_string()
}
}