ag_agent/app_server/error.rs
1use std::error::Error;
2
3use crate::app_server_transport::AppServerTransportError;
4
5/// Typed error returned by app-server infrastructure operations.
6///
7/// Wraps transport failures, prompt rendering issues, lock errors, and
8/// provider-specific failures so callers can distinguish error categories
9/// without parsing opaque strings.
10#[derive(Debug, thiserror::Error)]
11pub enum AppServerError {
12 /// The user interrupted an in-flight app-server turn.
13 #[error("{0}")]
14 InterruptedByUser(String),
15
16 /// The session registry mutex is poisoned.
17 #[error("Failed to lock {provider} app-server session map")]
18 LockPoisoned {
19 /// Provider label for diagnostics.
20 provider: &'static str,
21 },
22
23 /// A prompt template or protocol instruction rendering failed.
24 #[error("{0}")]
25 PromptRender(String),
26
27 /// A provider-specific runtime startup or turn execution failure.
28 #[error("{0}")]
29 Provider(String),
30
31 /// Both the initial attempt and one retry after restart failed.
32 #[error(
33 "{provider} app-server failed, then retry failed after restart: first error: \
34 {first_error}; retry error: {retry_error}"
35 )]
36 RetryExhausted {
37 /// Provider label for diagnostics.
38 provider: &'static str,
39 /// Error message from the first failed attempt.
40 first_error: String,
41 /// Error message from the retry attempt after restart.
42 retry_error: String,
43 },
44
45 /// An stdio transport or process communication failure.
46 #[error(transparent)]
47 Transport(Box<dyn Error + Send + Sync>),
48}
49
50impl From<AppServerTransportError> for AppServerError {
51 fn from(error: AppServerTransportError) -> Self {
52 Self::Transport(Box::new(error))
53 }
54}
55
56#[cfg(test)]
57#[path = "error_test.rs"]
58mod tests;