orion_core/error.rs
1use serde::Serialize;
2
3/// Errors from the Orion 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, or a reachable
21 /// endpoint that returned an error status).
22 #[error("Backend error: {0}")]
23 Backend(String),
24
25 /// The backend endpoint could not be reached - connection refused, DNS
26 /// failure, timeout, or a dropped connection mid-response. No response was
27 /// received, so the request may be safe to retry or fail over. Distinct from
28 /// [`Backend`](CoreError::Backend), which means the endpoint answered with an
29 /// error.
30 #[error("Backend unreachable: {0}")]
31 BackendUnreachable(String),
32
33 /// Context preparation failed (e.g. the prompt cannot fit the budget).
34 #[error("Context error: {0}")]
35 Context(String),
36
37 /// A tool failed to execute or no tool matched the requested name.
38 #[error("Tool error: {0}")]
39 Tool(String),
40
41 /// Agent-level logic error (e.g. an empty prompt).
42 #[error("Agent error: {0}")]
43 Agent(String),
44
45 /// Generation was cancelled via the abort flag.
46 #[error("Aborted")]
47 Aborted,
48}
49
50impl Serialize for CoreError {
51 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
52 where
53 S: serde::Serializer,
54 {
55 serializer.serialize_str(&self.to_string())
56 }
57}
58
59/// Convenience alias for a `Result` whose error is [`CoreError`].
60pub type CoreResult<T> = Result<T, CoreError>;