Skip to main content

dryice/
error.rs

1//! Error types for the `dryice` crate.
2
3use thiserror::Error;
4
5/// Top-level error type for all `dryice` operations.
6///
7/// This enum is organized into broad categories: transport/IO errors,
8/// configuration errors, input-record validity errors, format identity
9/// and version errors, structural corruption errors, unsupported
10/// feature errors, and integrity/decode failures.
11#[derive(Debug, Error)]
12pub enum DryIceError {
13    /// An underlying I/O error occurred.
14    #[error("I/O error: {0}")]
15    Io(#[from] std::io::Error),
16
17    /// The writer configuration is invalid.
18    #[error("invalid writer configuration: {0}")]
19    InvalidWriterConfiguration(&'static str),
20
21    /// The reader configuration is invalid.
22    #[error("invalid reader configuration: {0}")]
23    InvalidReaderConfiguration(&'static str),
24
25    /// Sequence and quality lengths do not match.
26    #[error("sequence and quality lengths differ: sequence={sequence_len}, quality={quality_len}")]
27    MismatchedSequenceAndQualityLengths {
28        /// Length of the sequence field.
29        sequence_len: usize,
30        /// Length of the quality field.
31        quality_len: usize,
32    },
33
34    /// A required record field is missing or empty.
35    #[error("record is missing required field: {field}")]
36    MissingRequiredField {
37        /// Name of the missing field.
38        field: &'static str,
39    },
40
41    /// Sequence data is not valid for the selected encoding.
42    #[error("invalid sequence encoding input: {message}")]
43    InvalidSequenceInput {
44        /// Description of the problem.
45        message: &'static str,
46    },
47
48    /// Quality data is not valid for the selected encoding.
49    #[error("invalid quality encoding input: {message}")]
50    InvalidQualityInput {
51        /// Description of the problem.
52        message: &'static str,
53    },
54
55    /// The file uses a format version this build does not support.
56    #[error("unsupported format version: {version}")]
57    UnsupportedFormatVersion {
58        /// The version number found in the file header.
59        version: u32,
60    },
61
62    /// The file does not begin with valid `dryice` magic bytes.
63    #[error("invalid file magic bytes")]
64    InvalidMagic,
65
66    /// A block header could not be parsed.
67    #[error("corrupt block header: {message}")]
68    CorruptBlockHeader {
69        /// Description of the corruption.
70        message: &'static str,
71    },
72
73    /// Block layout metadata is inconsistent or unreadable.
74    #[error("corrupt block layout: {message}")]
75    CorruptBlockLayout {
76        /// Description of the corruption.
77        message: &'static str,
78    },
79
80    /// A record index entry is corrupt or out of range.
81    #[error("corrupt record index at entry {entry}: {message}")]
82    CorruptRecordIndex {
83        /// Zero-based index of the problematic entry.
84        entry: usize,
85        /// Description of the corruption.
86        message: &'static str,
87    },
88
89    /// A section that should be present in this block is missing.
90    #[error("section `{section}` is missing but required by this block")]
91    MissingRequiredSection {
92        /// Name of the missing section.
93        section: &'static str,
94    },
95
96    /// A section is present but should not be for this block configuration.
97    #[error("section `{section}` is present but not valid for this block")]
98    UnexpectedSection {
99        /// Name of the unexpected section.
100        section: &'static str,
101    },
102
103    /// A block checksum did not match the computed value.
104    #[error("block checksum mismatch")]
105    ChecksumMismatch,
106
107    /// A record could not be decoded from block data.
108    #[error("record {record_index} could not be decoded: {message}")]
109    RecordDecode {
110        /// Zero-based index of the record within the block.
111        record_index: usize,
112        /// Description of the decode failure.
113        message: &'static str,
114    },
115
116    /// Record-key metadata in the block does not match the configured key type.
117    #[error("record-key metadata does not match the configured key type")]
118    RecordKeyTypeMismatch,
119
120    /// A record-key section is required but missing.
121    #[error("record-key section is missing from this block")]
122    MissingRecordKeySection,
123
124    /// A record-key encoding or decoding operation failed.
125    #[error("invalid record-key encoding: {message}")]
126    InvalidRecordKeyEncoding {
127        /// Description of the problem.
128        message: &'static str,
129    },
130
131    /// The block's sequence codec tag does not match the reader's configured codec.
132    #[error(
133        "sequence codec mismatch: file contains tag {found:?}, but reader expects {expected:?}"
134    )]
135    SequenceCodecMismatch {
136        /// The tag the reader expected.
137        expected: [u8; 16],
138        /// The tag found in the block header.
139        found: [u8; 16],
140    },
141
142    /// The block's quality codec tag does not match the reader's configured codec.
143    #[error("quality codec mismatch: file contains tag {found:?}, but reader expects {expected:?}")]
144    QualityCodecMismatch {
145        /// The tag the reader expected.
146        expected: [u8; 16],
147        /// The tag found in the block header.
148        found: [u8; 16],
149    },
150
151    /// The block's name codec tag does not match the reader's configured codec.
152    #[error("name codec mismatch: file contains tag {found:?}, but reader expects {expected:?}")]
153    NameCodecMismatch {
154        /// The tag the reader expected.
155        expected: [u8; 16],
156        /// The tag found in the block header.
157        found: [u8; 16],
158    },
159
160    /// A value exceeds the maximum representable size for the format.
161    #[error("{field} exceeds u32 range")]
162    SectionOverflow {
163        /// Which field or section overflowed.
164        field: &'static str,
165    },
166}