Skip to main content

astrid_runtime/
error.rs

1//! Runtime error types.
2
3use thiserror::Error;
4
5/// Errors that can occur in the runtime.
6#[derive(Debug, Error)]
7pub enum RuntimeError {
8    /// Session not found.
9    #[error("Session not found: {session_id}")]
10    SessionNotFound {
11        /// The session ID.
12        session_id: String,
13    },
14
15    /// Session already exists.
16    #[error("Session already exists: {session_id}")]
17    SessionExists {
18        /// The session ID.
19        session_id: String,
20    },
21
22    /// LLM error.
23    #[error("LLM error: {0}")]
24    LlmError(#[from] astrid_llm::LlmError),
25
26    /// MCP error.
27    #[error("MCP error: {0}")]
28    McpError(#[from] astrid_mcp::McpError),
29
30    /// Audit error.
31    #[error("Audit error: {0}")]
32    AuditError(#[from] astrid_audit::AuditError),
33
34    /// Capability error.
35    #[error("Capability error: {0}")]
36    CapabilityError(#[from] astrid_capabilities::CapabilityError),
37
38    /// Security error.
39    #[error("Security error: {0}")]
40    SecurityError(#[from] astrid_core::SecurityError),
41
42    /// Storage error.
43    #[error("Storage error: {0}")]
44    StorageError(String),
45
46    /// Serialization error.
47    #[error("Serialization error: {0}")]
48    SerializationError(String),
49
50    /// Context overflow.
51    #[error("Context overflow: {current} tokens exceeds limit of {max}")]
52    ContextOverflow {
53        /// Current token count.
54        current: usize,
55        /// Maximum allowed.
56        max: usize,
57    },
58
59    /// Approval required.
60    #[error("Approval required for: {action}")]
61    ApprovalRequired {
62        /// The action requiring approval.
63        action: String,
64    },
65
66    /// Approval denied.
67    #[error("Approval denied: {reason}")]
68    ApprovalDenied {
69        /// Reason for denial.
70        reason: String,
71    },
72
73    /// Configuration error.
74    #[error("Configuration error: {0}")]
75    ConfigError(String),
76
77    /// Sub-agent error.
78    #[error("Sub-agent error: {0}")]
79    SubAgentError(String),
80
81    /// IO error.
82    #[error("IO error: {0}")]
83    IoError(#[from] std::io::Error),
84}
85
86/// Result type for runtime operations.
87pub type RuntimeResult<T> = Result<T, RuntimeError>;