Skip to main content

sage_runtime/
error.rs

1//! Error types for the Sage runtime.
2
3use thiserror::Error;
4
5/// Result type for Sage operations.
6pub type SageResult<T> = Result<T, SageError>;
7
8/// Error type for Sage runtime errors.
9#[derive(Debug, Error)]
10pub enum SageError {
11    /// Error from LLM inference.
12    #[error("LLM error: {0}")]
13    Llm(String),
14
15    /// Error from agent execution.
16    #[error("Agent error: {0}")]
17    Agent(String),
18
19    /// Type mismatch at runtime.
20    #[error("Type error: expected {expected}, got {got}")]
21    Type { expected: String, got: String },
22
23    /// HTTP request error.
24    #[error("HTTP error: {0}")]
25    Http(#[from] reqwest::Error),
26
27    /// JSON parsing error.
28    #[error("JSON error: {0}")]
29    Json(#[from] serde_json::Error),
30
31    /// Agent task was cancelled or panicked.
32    #[error("Agent task failed: {0}")]
33    JoinError(String),
34}
35
36impl From<tokio::task::JoinError> for SageError {
37    fn from(e: tokio::task::JoinError) -> Self {
38        SageError::JoinError(e.to_string())
39    }
40}