gluesql_json_storage/
error.rs1use {gluesql_core::error::Error, thiserror::Error};
2
3pub trait ResultExt<T, E: ToString> {
4 fn map_storage_err(self) -> Result<T, Error>;
5}
6
7impl<T, E: ToString> ResultExt<T, E> for std::result::Result<T, E> {
8 fn map_storage_err(self) -> Result<T, Error> {
9 self.map_err(|e| e.to_string()).map_err(Error::StorageMsg)
10 }
11}
12
13pub trait OptionExt<T, E: ToString> {
14 fn map_storage_err(self, error: E) -> Result<T, Error>;
15}
16
17impl<T, E: ToString> OptionExt<T, E> for std::option::Option<T> {
18 fn map_storage_err(self, error: E) -> Result<T, Error> {
19 self.ok_or_else(|| error.to_string())
20 .map_err(Error::StorageMsg)
21 }
22}
23
24#[derive(Error, Debug)]
25pub enum JsonStorageError {
26 #[error("file not found")]
27 FileNotFound,
28
29 #[error("table does not exist")]
30 TableDoesNotExist,
31
32 #[error("column does not exist: {0}")]
33 ColumnDoesNotExist(String),
34
35 #[error("table name does not match with file")]
36 TableNameDoesNotMatchWithFile,
37
38 #[error("both {0}.jsonl and {0}.json files exist. remove or rename one")]
39 BothJsonlAndJsonExist(String),
40
41 #[error("invalid log file content: {0}")]
42 InvalidJsonContent(String),
43
44 #[error("json object type is required")]
45 JsonObjectTypeRequired,
46
47 #[error("json array type is required")]
48 JsonArrayTypeRequired,
49}