Skip to main content

rustalign_common/
error.rs

1//! Error types for RustAlign
2
3use std::path::PathBuf;
4
5/// Main error type for RustAlign
6#[derive(thiserror::Error, Debug)]
7pub enum RustAlignError {
8    /// I/O error
9    #[error("I/O error: {0}")]
10    Io(#[from] std::io::Error),
11
12    /// Invalid file format
13    #[error("Invalid file format: {0}")]
14    InvalidFormat(String),
15
16    /// Invalid nucleotide
17    #[error("Invalid nucleotide: {0}")]
18    InvalidNucleotide(u8),
19
20    /// Index file corrupted
21    #[error("Index file corrupted: {path}")]
22    IndexCorrupted {
23        /// Path to the corrupted index file
24        path: PathBuf,
25    },
26
27    /// Invalid index version
28    #[error("Invalid index version: expected {expected}, got {actual}")]
29    InvalidIndexVersion {
30        /// Expected version number
31        expected: u32,
32        /// Actual version number found
33        actual: u32,
34    },
35
36    /// Read too long
37    #[error("Read length {len} exceeds maximum {max}")]
38    ReadTooLong {
39        /// Length of the read
40        len: usize,
41        /// Maximum allowed length
42        max: usize,
43    },
44
45    /// Alignment failed
46    #[error("Alignment failed: {0}")]
47    AlignmentFailed(String),
48
49    /// Out of memory
50    #[error("Out of memory: requested {requested} bytes")]
51    OutOfMemory {
52        /// Number of bytes requested
53        requested: usize,
54    },
55
56    /// Invalid argument
57    #[error("Invalid argument: {0}")]
58    InvalidArgument(String),
59
60    /// Other error with context
61    #[error("{0}")]
62    Other(String),
63}
64
65/// Result type alias
66pub type Result<T> = std::result::Result<T, RustAlignError>;