1use ragit_fs::FileError;
2use ragit_pdl::JsonType;
3
4#[derive(Debug)]
5pub enum Error {
6 JsonTypeError {
7 expected: JsonType,
8 got: JsonType,
9 },
10 JsonObjectInvalidField(String),
11 JsonObjectMissingField(String),
12 InvalidModelName {
13 name: String,
14 candidates: Vec<String>,
15 },
16 InvalidApiProvider(String),
17 PdlError(ragit_pdl::Error),
18 FileError(FileError),
19 ApiKeyNotFound { env_var: Option<String> },
20 StdIoError(std::io::Error),
21 CannotReadImage(String ),
22
23 NoTry,
25
26 ReqwestError(reqwest::Error),
28
29 JsonSerdeError(serde_json::Error),
31
32 TeraError(tera::Error),
34
35 WrongSchema(String),
36 ServerError {
37 status_code: u16,
38 body: Result<String, reqwest::Error>,
39 },
40 UnsupportedMediaFormat {
41 extension: Option<String>,
42 },
43 TestModel,
44}
45
46impl From<std::io::Error> for Error {
47 fn from(e: std::io::Error) -> Error {
48 Error::StdIoError(e)
49 }
50}
51
52impl From<ragit_pdl::Error> for Error {
53 fn from(e: ragit_pdl::Error) -> Error {
54 match e {
55 ragit_pdl::Error::FileError(e) => Error::FileError(e),
56 ragit_pdl::Error::JsonTypeError { expected, got } => Error::JsonTypeError { expected, got },
57 ragit_pdl::Error::JsonSerdeError(e) => Error::JsonSerdeError(e),
58 ragit_pdl::Error::TeraError(e) => Error::TeraError(e),
59 _ => Error::PdlError(e),
60 }
61 }
62}
63
64impl From<FileError> for Error {
65 fn from(e: FileError) -> Error {
66 Error::FileError(e)
67 }
68}
69
70impl From<reqwest::Error> for Error {
71 fn from(e: reqwest::Error) -> Error {
72 Error::ReqwestError(e)
73 }
74}
75
76impl From<serde_json::Error> for Error {
77 fn from(e: serde_json::Error) -> Error {
78 Error::JsonSerdeError(e)
79 }
80}
81
82impl From<tera::Error> for Error {
83 fn from(e: tera::Error) -> Error {
84 Error::TeraError(e)
85 }
86}