Skip to main content

systemprompt_agent/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum TaskError {
5    #[error("Task UUID missing from database row")]
6    MissingTaskUuid,
7
8    #[error("Agent name not found for task {task_id}")]
9    MissingAgentName { task_id: String },
10
11    #[error("Context ID missing from database row")]
12    MissingContextId,
13
14    #[error("Invalid task state: {state}")]
15    InvalidTaskState { state: String },
16
17    #[error("Missing required field: {field}")]
18    MissingField { field: String },
19
20    #[error("Invalid datetime for field '{field}'")]
21    InvalidDatetime { field: String },
22
23    #[error("JSON parse error for field '{field}': {source}")]
24    JsonParse {
25        field: String,
26        #[source]
27        source: serde_json::Error,
28    },
29
30    #[error("Metadata parse error: {0}")]
31    InvalidMetadata(#[from] serde_json::Error),
32
33    #[error("Empty task ID provided")]
34    EmptyTaskId,
35
36    #[error("Invalid task ID format: {id}")]
37    InvalidTaskIdFormat { id: String },
38
39    #[error("Message ID missing from database row")]
40    MissingMessageId,
41
42    #[error("Tool name missing for tool execution")]
43    MissingToolName,
44
45    #[error("Tool call ID missing for tool execution")]
46    MissingCallId,
47
48    #[error("Created timestamp missing from database")]
49    MissingCreatedTimestamp,
50
51    #[error("Database error: {0}")]
52    Database(#[from] anyhow::Error),
53}
54
55#[derive(Debug, Error)]
56pub enum ContextError {
57    #[error("Context UUID missing from database row")]
58    MissingUuid,
59
60    #[error("Context name missing from database row")]
61    MissingName,
62
63    #[error("User ID missing from database row")]
64    MissingUserId,
65
66    #[error("Missing required field: {field}")]
67    MissingField { field: String },
68
69    #[error("Invalid datetime for field '{field}'")]
70    InvalidDatetime { field: String },
71
72    #[error("JSON parse error for field '{field}': {source}")]
73    JsonParse {
74        field: String,
75        #[source]
76        source: serde_json::Error,
77    },
78
79    #[error("Role serialization error: {0}")]
80    RoleSerialization(#[from] serde_json::Error),
81
82    #[error("Database error: {0}")]
83    Database(#[from] anyhow::Error),
84}
85
86#[derive(Debug, Error)]
87pub enum ArtifactError {
88    #[error("Artifact UUID missing from database row")]
89    MissingUuid,
90
91    #[error("Artifact type missing from database row")]
92    MissingType,
93
94    #[error("Context ID missing for artifact")]
95    MissingContextId,
96
97    #[error("Missing required field: {field}")]
98    MissingField { field: String },
99
100    #[error("Invalid datetime for field '{field}'")]
101    InvalidDatetime { field: String },
102
103    #[error("JSON parse error for field '{field}': {source}")]
104    JsonParse {
105        field: String,
106        #[source]
107        source: serde_json::Error,
108    },
109
110    #[error("Invalid tool response schema: expected {expected}, found keys: {actual_keys:?}")]
111    InvalidSchema {
112        expected: &'static str,
113        actual_keys: Vec<String>,
114        #[source]
115        source: serde_json::Error,
116    },
117
118    #[error("Metadata parse error: {0}")]
119    InvalidMetadata(#[from] serde_json::Error),
120
121    #[error("Database error: {0}")]
122    Database(#[from] anyhow::Error),
123
124    #[error("Transform error: {0}")]
125    Transform(String),
126
127    #[error("Metadata validation error: {0}")]
128    MetadataValidation(String),
129}
130
131#[derive(Debug, Error)]
132pub enum ProtocolError {
133    #[error("Tool name missing in tool call")]
134    MissingToolName,
135
136    #[error("Tool result error flag is required but was not provided")]
137    MissingErrorFlag,
138
139    #[error("Message ID missing")]
140    MissingMessageId,
141
142    #[error("Request ID missing")]
143    MissingRequestId,
144
145    #[error("Latency value missing or invalid")]
146    InvalidLatency,
147
148    #[error("Validation failed: {0}")]
149    ValidationFailed(String),
150
151    #[error("JSON parse error: {0}")]
152    JsonParse(#[from] serde_json::Error),
153
154    #[error("Database error: {0}")]
155    Database(#[from] anyhow::Error),
156}
157
158#[derive(Debug, Error)]
159pub enum AgentError {
160    #[error("Task error: {0}")]
161    Task(#[from] TaskError),
162
163    #[error("Context error: {0}")]
164    Context(#[from] ContextError),
165
166    #[error("Artifact error: {0}")]
167    Artifact(#[from] ArtifactError),
168
169    #[error("A2A protocol error: {0}")]
170    Protocol(#[from] ProtocolError),
171
172    #[error("Repository error: {0}")]
173    Repository(#[from] anyhow::Error),
174
175    #[error("Database error: {0}")]
176    Database(String),
177}