Skip to main content

mdql_core/
errors.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum MdqlError {
5    #[error("Schema not found: {0}")]
6    SchemaNotFound(String),
7
8    #[error("Schema invalid: {0}")]
9    SchemaInvalid(String),
10
11    #[error("Parse error: {0}")]
12    Parse(String),
13
14    #[error("Query parse error: {0}")]
15    QueryParse(String),
16
17    #[error("Query execution error: {0}")]
18    QueryExecution(String),
19
20    #[error("Database config error: {0}")]
21    DatabaseConfig(String),
22
23    #[error("Journal recovery error: {0}")]
24    JournalRecovery(String),
25
26    #[error("{0}")]
27    General(String),
28
29    #[error("IO error: {0}")]
30    Io(#[from] std::io::Error),
31}
32
33pub type Result<T> = std::result::Result<T, MdqlError>;
34
35#[derive(Debug, Clone, PartialEq)]
36pub struct ValidationError {
37    pub file_path: String,
38    pub error_type: String,
39    pub field: Option<String>,
40    pub message: String,
41    pub line_number: Option<usize>,
42}
43
44impl std::fmt::Display for ValidationError {
45    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46        if let Some(line) = self.line_number {
47            write!(f, "{}:{}: {}", self.file_path, line, self.message)
48        } else {
49            write!(f, "{}: {}", self.file_path, self.message)
50        }
51    }
52}