use std::io; #[derive(Debug, thiserror::Error)] pub enum SshError { #[error("authentication rejected: {0}")] AuthRejected(String), #[error("failed to load host key: {0}")] KeyLoadFailed(String), #[error("repository not found: {0}")] RepoNotFound(String), #[error("permission denied: {0}")] PermissionDenied(String), #[error("invalid command: {0}")] InvalidCommand(String), #[error("io error: {0}")] Io(#[from] io::Error), #[error("db error: {0}")] Db(#[from] db::conn::SqlxError), #[error("ssh error: {0}")] Ssh(#[from] russh::Error), #[error("internal error: {0}")] Internal(String), } pub type SshResult = Result; impl From for SshError { fn from(err: gitsmart::SmartError) -> Self { match err { gitsmart::SmartError::Unauthorized(m) | gitsmart::SmartError::BadRequest(m) => Self::AuthRejected(m), gitsmart::SmartError::Conflict(m) => Self::Internal(m), gitsmart::SmartError::Forbidden(m) => Self::PermissionDenied(m), gitsmart::SmartError::NotFound(m) => Self::RepoNotFound(m), gitsmart::SmartError::Internal(m) => Self::Internal(m), gitsmart::SmartError::Io(e) => Self::Io(e), gitsmart::SmartError::Redis(e) => Self::Internal(format!("redis error: {e}")), other => Self::Internal(other.to_string()), } } }