use agent_os_sidecar::protocol::ProtocolCodecError;
#[derive(thiserror::Error, Debug)]
pub enum ClientError {
#[error("Path must be absolute: {0}")]
PathNotAbsolute(String),
#[error("Path must be normalized: {0}")]
PathNotNormalized(String),
#[error("Path is read-only: {0}")]
PathReadOnly(String),
#[error("Process not found: {0}")]
ProcessNotFound(u32),
#[error("shell not found: {0}")]
ShellNotFound(String),
#[error("session not found: {0}")]
SessionNotFound(String),
#[error("kernel error [{code}]: {message}")]
Kernel { code: String, message: String },
#[error("invalid schedule: {0}")]
InvalidSchedule(String),
#[error("schedule is in the past: {0}")]
PastSchedule(String),
#[error("transport error: {0}")]
Transport(#[from] ProtocolCodecError),
#[error("sidecar error: {0}")]
Sidecar(String),
}
impl ClientError {
pub fn batch_message(&self) -> String {
match self {
ClientError::Kernel { code, message } => {
if message.starts_with(&format!("{code}:")) {
message.clone()
} else {
format!("{code}: {message}")
}
}
ClientError::PathNotAbsolute(_)
| ClientError::PathNotNormalized(_)
| ClientError::PathReadOnly(_)
| ClientError::ProcessNotFound(_)
| ClientError::ShellNotFound(_)
| ClientError::SessionNotFound(_)
| ClientError::InvalidSchedule(_)
| ClientError::PastSchedule(_)
| ClientError::Transport(_)
| ClientError::Sidecar(_) => self.to_string(),
}
}
}
pub type ClientResult<T> = std::result::Result<T, ClientError>;