Skip to main content

data_preprocess/
error.rs

1use chrono::NaiveDateTime;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum DataError {
6    #[cfg(feature = "duckdb-backend")]
7    #[error("DuckDB error: {0}")]
8    DuckDb(#[from] duckdb::Error),
9
10    #[error("CSV error: {0}")]
11    Csv(#[from] csv::Error),
12
13    #[cfg(feature = "parquet")]
14    #[error("Polars error: {0}")]
15    Polars(#[from] polars::error::PolarsError),
16
17    #[error("IO error: {0}")]
18    Io(#[from] std::io::Error),
19
20    #[error("Invalid timestamp: {0}")]
21    InvalidTimestamp(String),
22
23    #[error("Data traversal cancelled")]
24    Cancelled,
25
26    #[error("invalid scan bounds: from {from} is after to {to}")]
27    InvalidScanBounds {
28        from: NaiveDateTime,
29        to: NaiveDateTime,
30    },
31
32    #[error("Parquet scan rows per read must be greater than zero")]
33    InvalidScanReadSize,
34
35    #[error("invalid Parquet date partition filename: {0}")]
36    InvalidDatePartition(String),
37
38    #[error("Parquet partition changed during scan: {path}")]
39    ParquetPartitionChanged { path: String },
40
41    #[error("non-monotonic Parquet timestamps in {path}: {current} follows {previous}")]
42    NonMonotonicParquetData {
43        path: String,
44        previous: NaiveDateTime,
45        current: NaiveDateTime,
46    },
47
48    #[error("Invalid timeframe: {0}")]
49    InvalidTimeframe(String),
50
51    #[error("Could not extract symbol from filename: {0}")]
52    SymbolExtraction(String),
53
54    #[error("Parse error in {file}:{line} — {message}")]
55    ParseError {
56        file: String,
57        line: usize,
58        message: String,
59    },
60
61    #[error("{0}")]
62    Other(String),
63}
64
65pub type Result<T> = std::result::Result<T, DataError>;