data_matrix/
errors.rs

1use thiserror::Error;
2
3/// Custom error type for DataMatrix operations.
4#[derive(Debug, Error)]
5#[non_exhaustive]
6pub enum Error {
7    /// Row or column labels count does not match number of rows / columns
8    #[error("The number of labels {expected} does not match the count anticipated from the data matrix {actual}")]
9    IncorrectMatrixLabels { expected: usize, actual: usize },
10
11    /// Line does not have enough columns.
12    #[error("Line {line} does not contain enough columns (need at least {needed}): '{content}'")]
13    NotEnoughColumns {
14        line: usize,
15        needed: usize,
16        content: String,
17    },
18
19    /// More than one column found when expecting single column input.
20    #[error("Line {line} has too many columns when expecting single value: '{content}'")]
21    TooManyColumns { line: usize, content: String },
22
23    /// Parsing error at a line.
24    #[error("Invalid value at line {line}: '{content}'")]
25    ParseError { line: usize, content: String },
26
27    /// Incorrect number of data values; expected a square matrix packed row-wise.
28    #[error(
29        "Incorrect number of data values: {n_data}; expected a square matrix packed row-wise."
30    )]
31    WrongNumberOfData { n_data: usize },
32
33    /// Generic I/O error.
34    #[error("I/O error: {0}")]
35    IoError(#[from] std::io::Error),
36}