chore: initial commit for phase04

This commit is contained in:
hibna
2026-02-21 15:50:35 +03:00
parent d0c20581b6
commit 218452706c
15 changed files with 4310 additions and 8 deletions
+52
View File
@@ -0,0 +1,52 @@
use thiserror::Error;
#[derive(Error, Debug)]
pub enum DaemonError {
#[error("Docker error: {0}")]
Docker(#[from] bollard::errors::Error),
#[error("Server not found: {0}")]
ServerNotFound(String),
#[error("Server already exists: {0}")]
ServerAlreadyExists(String),
#[error("Invalid state transition: {current} -> {requested}")]
InvalidStateTransition { current: String, requested: String },
#[error("Filesystem error: {0}")]
Filesystem(String),
#[error("Path traversal attempt: {0}")]
PathTraversal(String),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Authentication failed")]
AuthFailed,
#[error("{0}")]
Internal(String),
}
impl From<DaemonError> for tonic::Status {
fn from(err: DaemonError) -> Self {
match &err {
DaemonError::ServerNotFound(_) => tonic::Status::not_found(err.to_string()),
DaemonError::ServerAlreadyExists(_) => {
tonic::Status::already_exists(err.to_string())
}
DaemonError::InvalidStateTransition { .. } => {
tonic::Status::failed_precondition(err.to_string())
}
DaemonError::PathTraversal(_) => {
tonic::Status::permission_denied(err.to_string())
}
DaemonError::AuthFailed => {
tonic::Status::unauthenticated(err.to_string())
}
_ => tonic::Status::internal(err.to_string()),
}
}
}