Skip to main content

csv_slice/
error.rs

1// Import the thiserror crate which provides macros for easier error handling in Rust
2use thiserror::Error;
3
4/// CsvSliceError is the main error type for the csv-slice library.
5/// 
6/// This enum represents all possible errors that can occur when working with the csv-slice library.
7/// It uses the thiserror crate to automatically implement the Error trait and provide
8/// formatted error messages.
9///
10/// # Error Types
11/// - `Csv`: Represents errors from the csv crate when parsing or processing CSV files
12/// - `Io`: Represents standard I/O errors that may occur when reading files
13/// - `ColumnNotFound`: A custom error that occurs when a requested column name doesn't exist in the CSV
14#[derive(Error, Debug)]
15pub enum CsvSliceError {
16    /// Wraps errors from the csv crate
17    /// The #[from] attribute automatically implements From<csv::Error> for CsvSliceError
18    #[error("CSV error: {0}")]
19    Csv(#[from] csv::Error),
20    
21    /// Wraps standard I/O errors
22    /// The #[from] attribute automatically implements From<std::io::Error> for CsvSliceError
23    #[error("IO error: {0}")]
24    Io(#[from] std::io::Error),
25    
26    /// Custom error for when a requested column name is not found in the CSV headers
27    /// Contains the name of the column that was not found
28    #[error("Column not found: {0}")]
29    ColumnNotFound(String)
30}