1use std::fmt;
4
5pub type Result<T> = std::result::Result<T, RagError>;
7
8#[derive(Debug, thiserror::Error)]
10pub enum RagError {
11 #[error("configuration error: {0}")]
13 Config(String),
14
15 #[error("document conversion failed: {0}")]
17 Conversion(String),
18
19 #[error("embedding error: {0}")]
21 Embedding(String),
22
23 #[error("store error: {0}")]
25 Store(String),
26
27 #[error("llm error: {0}")]
29 Llm(String),
30
31 #[error("source error: {0}")]
33 Source(String),
34
35 #[error("queue error: {0}")]
37 Queue(String),
38
39 #[error("http error: {0}")]
41 Http(String),
42
43 #[error("io error: {0}")]
45 Io(#[from] std::io::Error),
46
47 #[error("json error: {0}")]
49 Json(#[from] serde_json::Error),
50
51 #[error("backend '{0}' is not available: rebuild with the '{1}' cargo feature")]
53 FeatureDisabled(String, String),
54}
55
56impl RagError {
57 pub fn config(msg: impl fmt::Display) -> Self {
59 RagError::Config(msg.to_string())
60 }
61}
62
63impl From<reqwest::Error> for RagError {
64 fn from(e: reqwest::Error) -> Self {
65 RagError::Http(e.to_string())
66 }
67}
68
69impl From<sqlx::Error> for RagError {
70 fn from(e: sqlx::Error) -> Self {
71 RagError::Store(e.to_string())
72 }
73}