Skip to main content

solo_core/
error.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Workspace-wide error type.
4
5use thiserror::Error;
6
7pub type Result<T> = std::result::Result<T, Error>;
8
9#[derive(Debug, Error)]
10pub enum Error {
11    #[error("storage error: {0}")]
12    Storage(String),
13
14    #[error("vector index error: {0}")]
15    VectorIndex(String),
16
17    #[error("embedder error: {0}")]
18    Embedder(String),
19
20    #[error("embedder protocol violation: {0}")]
21    EmbedderProtocol(&'static str),
22
23    #[error("LLM client error: {0}")]
24    Llm(String),
25
26    #[error("steward error: {0}")]
27    Steward(String),
28
29    #[error("invalid input: {0}")]
30    InvalidInput(String),
31
32    #[error("not found: {0}")]
33    NotFound(String),
34
35    #[error("conflict: {0}")]
36    Conflict(String),
37
38    /// v0.8.1 P3: a request was rejected by a policy gate rather than a
39    /// data-shape problem. Used today by the per-tenant `quota_bytes`
40    /// enforcement path; the transport layer translates this to a 403
41    /// Forbidden in HTTP and the audit log records `result =
42    /// 'forbidden'`.
43    #[error("forbidden: {0}")]
44    Forbidden(String),
45
46    #[error("io error: {0}")]
47    Io(#[from] std::io::Error),
48
49    #[error("serialization error: {0}")]
50    Serde(#[from] serde_json::Error),
51
52    #[error("uuid error: {0}")]
53    Uuid(#[from] uuid::Error),
54
55    #[error("other: {0}")]
56    Other(String),
57}
58
59impl Error {
60    pub fn storage(msg: impl Into<String>) -> Self {
61        Self::Storage(msg.into())
62    }
63    pub fn vector_index(msg: impl Into<String>) -> Self {
64        Self::VectorIndex(msg.into())
65    }
66    pub fn embedder(msg: impl Into<String>) -> Self {
67        Self::Embedder(msg.into())
68    }
69    pub fn llm(msg: impl Into<String>) -> Self {
70        Self::Llm(msg.into())
71    }
72    pub fn steward(msg: impl Into<String>) -> Self {
73        Self::Steward(msg.into())
74    }
75    pub fn invalid_input(msg: impl Into<String>) -> Self {
76        Self::InvalidInput(msg.into())
77    }
78    pub fn not_found(msg: impl Into<String>) -> Self {
79        Self::NotFound(msg.into())
80    }
81    pub fn conflict(msg: impl Into<String>) -> Self {
82        Self::Conflict(msg.into())
83    }
84    /// v0.8.1 P3: construct a Forbidden error (policy rejection).
85    pub fn forbidden(msg: impl Into<String>) -> Self {
86        Self::Forbidden(msg.into())
87    }
88}