Skip to main content

brainwires_datasets/
error.rs

1use thiserror::Error;
2
3/// Errors that can occur during dataset operations.
4#[derive(Error, Debug)]
5pub enum DatasetError {
6    /// I/O error reading or writing data.
7    #[error("I/O error: {0}")]
8    Io(#[from] std::io::Error),
9
10    /// JSON serialization or deserialization error.
11    #[error("JSON parse error: {0}")]
12    Json(#[from] serde_json::Error),
13
14    /// Dataset validation failed.
15    #[error("Validation error: {message}")]
16    Validation {
17        /// Description of the validation failure.
18        message: String,
19    },
20
21    /// Format conversion error between providers.
22    #[error("Format conversion error: {message}")]
23    FormatConversion {
24        /// Description of the conversion failure.
25        message: String,
26    },
27
28    /// Tokenizer encoding or decoding error.
29    #[error("Tokenizer error: {message}")]
30    Tokenizer {
31        /// Description of the tokenizer failure.
32        message: String,
33    },
34
35    /// Index is out of bounds for the dataset.
36    #[error("Index out of bounds: {index} (len: {len})")]
37    IndexOutOfBounds {
38        /// The requested index.
39        index: usize,
40        /// The actual length of the dataset.
41        len: usize,
42    },
43
44    /// The dataset is empty.
45    #[error("Empty dataset")]
46    EmptyDataset,
47
48    /// Generic error with a message.
49    #[error("{0}")]
50    Other(
51        /// Error message.
52        String,
53    ),
54}
55
56/// Convenience alias for `Result<T, DatasetError>`.
57pub type DatasetResult<T> = Result<T, DatasetError>;