Skip to main content

pipeline_service/
error.rs

1use std::fmt;
2
3pub type ServiceResult<T> = Result<T, ServiceError>;
4
5#[derive(Debug)]
6pub enum ServiceError {
7    NotFound(String),
8    InvalidInput(String),
9    Internal(String),
10    IoError(std::io::Error),
11    YamlError(serde_yaml::Error),
12}
13
14impl fmt::Display for ServiceError {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        match self {
17            ServiceError::NotFound(msg) => write!(f, "Not found: {}", msg),
18            ServiceError::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
19            ServiceError::Internal(msg) => write!(f, "Internal error: {}", msg),
20            ServiceError::IoError(e) => write!(f, "IO error: {}", e),
21            ServiceError::YamlError(e) => write!(f, "YAML error: {}", e),
22        }
23    }
24}
25
26impl std::error::Error for ServiceError {}
27
28impl From<std::io::Error> for ServiceError {
29    fn from(err: std::io::Error) -> Self {
30        ServiceError::IoError(err)
31    }
32}
33
34impl From<serde_yaml::Error> for ServiceError {
35    fn from(err: serde_yaml::Error) -> Self {
36        ServiceError::YamlError(err)
37    }
38}