redicat_lib/core/
error.rs1use thiserror::Error;
4
5#[derive(Error, Debug)]
6pub enum RedicatError {
7 #[error("IO error: {0}")]
8 Io(#[from] std::io::Error),
9
10 #[error("AnnData error: {0}")]
11 AnnData(#[from] anyhow::Error),
12
13 #[error("Polars error: {0}")]
14 Polars(#[from] polars::error::PolarsError),
15
16 #[error("Sparse matrix error: {0}")]
17 SparseMatrix(String),
18
19 #[error("Invalid input: {0}")]
20 InvalidInput(String),
21
22 #[error("File not found: {0}")]
23 FileNotFound(String),
24
25 #[error("Parse error: {0}")]
26 Parse(String),
27
28 #[error("Reference genome error: {0}")]
29 ReferenceGenome(String),
30
31 #[error("Data processing error: {0}")]
32 DataProcessing(String),
33
34 #[error("Threshold validation error: {field} must be between {min} and {max}, got {value}")]
35 ThresholdValidation {
36 field: String,
37 min: f64,
38 max: f64,
39 value: f64,
40 },
41
42 #[error("Dimension mismatch: expected {expected}, got {actual}")]
43 DimensionMismatch { expected: String, actual: String },
44
45 #[error("Configuration error: {0}")]
46 Config(String),
47
48 #[error("Empty data: {0}")]
49 EmptyData(String),
50}
51
52pub type Result<T> = std::result::Result<T, RedicatError>;
53
54impl From<nalgebra_sparse::SparseFormatError> for RedicatError {
55 fn from(err: nalgebra_sparse::SparseFormatError) -> Self {
56 RedicatError::SparseMatrix(format!("Sparse format error: {:?}", err))
57 }
58}