1use std::path::PathBuf;
2use thiserror::Error;
3
4pub type Result<T, E = Error> = std::result::Result<T, E>;
7
8#[derive(Error, Debug, PartialEq)]
9pub enum Error {
10 #[error("file not found: {path}")]
12 FileNotFound { path: PathBuf },
13 #[error("file could not be opened: {path}")]
14 FileOpen { path: String },
15 #[error("invalid (non-unicode) characters in path")]
16 NonUnicodePath,
17 #[error("failed to fetch region")]
18 Fetch,
19 #[error("error seeking to file offset")]
20 FileSeek,
21 #[error("error seeking to {contig:?}:{start} in indexed file")]
22 GenomicSeek { contig: String, start: u64 },
23 #[error("sequence {sequence} not found in index")]
24 UnknownSequence { sequence: String },
25 #[error("error setting threads for file reading")]
26 SetThreads,
27 #[error("failed to create htslib thread pool")]
28 ThreadPool,
29
30 #[error("failed to write BAM/BCF record (out of disk space?)")]
31 WriteRecord,
32
33 #[error("The given position is too large to be converted to i64")]
35 FaidxPositionTooLarge,
36 #[error("bad conversion of sequence name")]
37 FaidxBadSeqName,
38 #[error("failed to build index for fasta file {path:?}")]
39 FaidxBuildFailed { path: std::path::PathBuf },
40
41 #[error("previous iterator generation failed")]
43 TabixNoIter,
44 #[error("truncated tabix record")]
45 TabixTruncatedRecord,
46 #[error("invalid tabix index")]
47 TabixInvalidIndex,
48
49 #[error("error parsing CIGAR string: {msg}")]
51 BamParseCigar { msg: String },
52 #[error("unexpected CIGAR operation: {msg}")]
53 BamUnexpectedCigarOperation { msg: String },
54 #[error("error parsing SAM record: {rec}")]
55 BamParseSAM { rec: String },
56 #[error("invalid path to CRAM-reference {path}")]
57 BamInvalidReferencePath { path: PathBuf },
58 #[error("invalid compression level {level}")]
59 BamInvalidCompressionLevel { level: u32 },
60 #[error("unable to open SAM/BAM/CRAM file at {target}")]
61 BamOpen { target: String },
62 #[error("unable to open SAM/BAM/CRAM index for {target}; please create an index")]
63 BamInvalidIndex { target: String },
64 #[error("invalid record in SAM/BAM/CRAM file")]
65 BamInvalidRecord,
66 #[error("truncated record in SAM/BAM/CRAM file")]
67 BamTruncatedRecord,
68 #[error(
69 "format not indexable by htslib (format is detected as something else than SAM/BAM/CRAM)"
70 )]
71 BamNotIndexable,
72 #[error("failed to write BAM/CRAM index (out of disk space?)")]
73 BamWriteIndex,
74 #[error("failed to build BAM/CRAM index")]
75 BamBuildIndex,
76 #[error("failed to create SAM/BAM/CRAM pileup")]
77 BamPileup,
78 #[error("file is not sorted by position")]
79 BamUnsorted,
80
81 #[error("failed to add aux field (out of memory?)")]
83 BamAux,
84 #[error("provided string contains internal 0 byte(s)")]
85 BamAuxStringError,
86 #[error("failed to parse aux data")]
87 BamAuxParsingError,
88 #[error("the specified tag does could not be found")]
89 BamAuxTagNotFound,
90 #[error("data type of aux field is not known")]
91 BamAuxUnknownType,
92 #[error("failed to add aux field, tag is already present")]
93 BamAuxTagAlreadyPresent,
94
95 #[error("no base modification tag found for record")]
97 BamBaseModificationTagNotFound,
98 #[error("no base modification with the specified code found in record")]
99 BamBaseModificationTypeNotFound,
100 #[error("base modification iteration failed")]
101 BamBaseModificationIterationFailed,
102 #[error("base modification found too many modifications")]
103 BamBaseModificationTooManyMods,
104
105 #[error("error allocating internal data structure for BCF/VCF reader (out of memory?)")]
107 BcfAllocationError,
108 #[error("failed to open BCF/VCF from {target:?}")]
109 BcfOpen { target: String },
110 #[error("invalid record in BCF/VCF file")]
111 BcfInvalidRecord,
112 #[error("tag {tag} undefined in BCF/VCF header")]
113 BcfUndefinedTag { tag: String },
114 #[error("unexpected type for tag {tag} in BCF/VCF file")]
115 BcfUnexpectedType { tag: String },
116 #[error("tag {tag} missing from record {record} in BCF/VCF file")]
117 BcfMissingTag { tag: String, record: String },
118 #[error("error setting tag {tag} in BCF/VCF record (out of memory?)")]
119 BcfSetTag { tag: String },
120 #[error("ID {rid} not found in BCF/VCF header")]
121 BcfUnknownRID { rid: u32 },
122 #[error("contig {contig} not found in BCF/VCF header")]
123 BcfUnknownContig { contig: String },
124 #[error("ID {id} not found in BCF/VCF header")]
125 BcfUnknownID { id: String },
126 #[error("sample {name} not found in BCF/VCF header")]
127 BcfUnknownSample { name: String },
128 #[error("duplicate sample names given for subsetting BCF/VCF")]
129 BcfDuplicateSampleNames,
130 #[error("failed to set values in BCF/VCF record (out of memory?)")]
131 BcfSetValues,
132 #[error("failed to remove alleles in BCF/VCF record")]
133 BcfRemoveAlleles,
134 #[error("failed to render BCF record as string")]
135 BcfToString,
136
137 #[error("invalid compression level {level}")]
138 BgzfInvalidCompressionLevel { level: i8 },
139 #[error("failed setting hts reading options")]
140 HtsSetOpt,
141 #[error("failed calculating slow index statistics")]
142 SlowIdxStats,
143 #[error("invalid tid {tid}")]
144 InvalidTid { tid: i32 },
145 #[error("No sequences in the reference")]
146 NoSequencesInReference,
147}