systemprompt_agent/services/shared/
error.rs1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum AgentServiceError {
5 #[error("database operation failed: {0}")]
6 Database(String),
7
8 #[error("repository operation failed: {0}")]
9 Repository(String),
10
11 #[error("network request failed: {0}")]
12 Network(String),
13
14 #[error("authentication failed: {0}")]
15 Authentication(String),
16
17 #[error("authorization failed for resource: {0}")]
18 Authorization(String),
19
20 #[error("validation failed: {0}: {1}")]
21 Validation(String, String),
22
23 #[error("resource not found: {0}")]
24 NotFound(String),
25
26 #[error("service unavailable: {0}")]
27 ServiceUnavailable(String),
28
29 #[error("operation timed out after {0}ms")]
30 Timeout(u64),
31
32 #[error("configuration error: {0}: {1}")]
33 Configuration(String, String),
34
35 #[error("conflict: {0}")]
36 Conflict(String),
37
38 #[error("internal error: {0}")]
39 Internal(String),
40
41 #[error("logging error: {0}")]
42 Logging(String),
43
44 #[error("capacity exceeded: {0}")]
45 Capacity(String),
46}
47
48impl From<std::io::Error> for AgentServiceError {
49 fn from(err: std::io::Error) -> Self {
50 Self::Internal(format!("io: {err}"))
51 }
52}
53
54impl From<sqlx::Error> for AgentServiceError {
55 fn from(err: sqlx::Error) -> Self {
56 Self::Database(err.to_string())
57 }
58}
59
60impl From<crate::repository::RepositoryError> for AgentServiceError {
61 fn from(err: crate::repository::RepositoryError) -> Self {
62 Self::Repository(err.to_string())
63 }
64}
65
66impl From<systemprompt_database::RepositoryError> for AgentServiceError {
67 fn from(err: systemprompt_database::RepositoryError) -> Self {
68 Self::Repository(err.to_string())
69 }
70}
71
72impl From<crate::error::AgentError> for AgentServiceError {
73 fn from(err: crate::error::AgentError) -> Self {
74 Self::Internal(err.to_string())
75 }
76}
77
78impl From<reqwest::Error> for AgentServiceError {
79 fn from(err: reqwest::Error) -> Self {
80 Self::Network(
81 err.url()
82 .map_or_else(|| "unknown".to_string(), ToString::to_string),
83 )
84 }
85}
86
87pub type Result<T> = std::result::Result<T, AgentServiceError>;