Skip to main content

orion_core/
error.rs

1use serde::Serialize;
2
3/// Errors from the orion-core agent harness.
4///
5/// All variants are serializable (via [`serde::Serialize`]) for easy transport
6/// over IPC.
7///
8/// ```
9/// use orion_core::CoreError;
10///
11/// let err = CoreError::Backend("No model loaded".into());
12/// assert_eq!(err.to_string(), "Backend error: No model loaded");
13/// ```
14///
15/// This enum is `#[non_exhaustive]`: match it with a wildcard arm, as new
16/// variants may be added in a minor release.
17#[derive(Debug, thiserror::Error)]
18#[non_exhaustive]
19pub enum CoreError {
20    /// The LLM backend failed (no model loaded, inference error, etc.).
21    #[error("Backend error: {0}")]
22    Backend(String),
23
24    /// Context preparation failed (e.g. the prompt cannot fit the budget).
25    #[error("Context error: {0}")]
26    Context(String),
27
28    /// A tool failed to execute or no tool matched the requested name.
29    #[error("Tool error: {0}")]
30    Tool(String),
31
32    /// Agent-level logic error (e.g. an empty prompt).
33    #[error("Agent error: {0}")]
34    Agent(String),
35
36    /// Generation was cancelled via the abort flag.
37    #[error("Aborted")]
38    Aborted,
39}
40
41impl Serialize for CoreError {
42    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
43    where
44        S: serde::Serializer,
45    {
46        serializer.serialize_str(&self.to_string())
47    }
48}
49
50/// Convenience alias for a `Result` whose error is [`CoreError`].
51pub type CoreResult<T> = Result<T, CoreError>;