use thiserror::Error;
pub type Result<T> = std::result::Result<T, FgumiError>;
#[derive(Error, Debug)]
pub enum FgumiError {
#[error("Invalid parameter '{parameter}': {reason}")]
InvalidParameter {
parameter: String,
reason: String,
},
#[error("Invalid frequency threshold: {value} (must be between {min} and {max})")]
InvalidFrequency {
value: f64,
min: f64,
max: f64,
},
#[error("Invalid quality threshold: {value} (must be between 0 and {max})")]
InvalidQuality {
value: u8,
max: u8,
},
#[error("Invalid {file_type} file '{path}': {reason}")]
InvalidFileFormat {
file_type: String,
path: String,
reason: String,
},
#[error("Reference sequence '{ref_name}' not found in header")]
ReferenceNotFound {
ref_name: String,
},
#[error("Invalid memory size: {reason}")]
InvalidMemorySize {
reason: String,
},
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_invalid_parameter() {
let error = FgumiError::InvalidParameter {
parameter: "min-reads".to_string(),
reason: "must be >= 1".to_string(),
};
let msg = format!("{error}");
assert!(msg.contains("Invalid parameter 'min-reads'"));
assert!(msg.contains("must be >= 1"));
}
#[test]
fn test_invalid_frequency() {
let error = FgumiError::InvalidFrequency { value: 1.5, min: 0.0, max: 1.0 };
let msg = format!("{error}");
assert!(msg.contains("1.5"));
assert!(msg.contains("between 0 and 1"));
}
#[test]
fn test_invalid_file_format() {
let error = FgumiError::InvalidFileFormat {
file_type: "BAM".to_string(),
path: "/path/to/file.bam".to_string(),
reason: "truncated file".to_string(),
};
let msg = format!("{error}");
assert!(msg.contains("Invalid BAM file"));
assert!(msg.contains("truncated file"));
}
#[test]
fn test_invalid_memory_size() {
let error =
FgumiError::InvalidMemorySize { reason: "Memory size cannot be empty".to_string() };
let msg = format!("{error}");
assert!(msg.contains("Invalid memory size"));
assert!(msg.contains("cannot be empty"));
}
#[test]
fn test_reference_not_found() {
let error = FgumiError::ReferenceNotFound { ref_name: "chr1".to_string() };
let msg = format!("{error}");
assert!(msg.contains("Reference sequence 'chr1' not found"));
}
}