extended_htslib/
errors.rs1use 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("error parsing CS record: {rec}")]
57 BamParseCS { rec: String },
58 #[error("error parsing MD record: {rec}")]
59 BamParseMD { rec: String },
60 #[error("invalid path to CRAM-reference {path}")]
61 BamInvalidReferencePath { path: PathBuf },
62 #[error("invalid compression level {level}")]
63 BamInvalidCompressionLevel { level: u32 },
64 #[error("unable to open SAM/BAM/CRAM file at {target}")]
65 BamOpen { target: String },
66 #[error("unable to open SAM/BAM/CRAM index for {target}; please create an index")]
67 BamInvalidIndex { target: String },
68 #[error("invalid record in SAM/BAM/CRAM file")]
69 BamInvalidRecord,
70 #[error("truncated record in SAM/BAM/CRAM file")]
71 BamTruncatedRecord,
72 #[error(
73 "format not indexable by htslib (format is detected as something else than SAM/BAM/CRAM)"
74 )]
75 BamNotIndexable,
76 #[error("failed to write BAM/CRAM index (out of disk space?)")]
77 BamWriteIndex,
78 #[error("failed to build BAM/CRAM index")]
79 BamBuildIndex,
80 #[error("failed to create SAM/BAM/CRAM pileup")]
81 BamPileup,
82 #[error("file is not sorted by position")]
83 BamUnsorted,
84 #[error("error parsing header")]
85 HeaderParse,
86
87 #[error("failed to add aux field (out of memory?)")]
89 BamAux,
90 #[error("provided string contains internal 0 byte(s)")]
91 BamAuxStringError,
92 #[error("failed to parse aux data")]
93 BamAuxParsingError,
94 #[error("the specified tag does could not be found")]
95 BamAuxTagNotFound,
96 #[error("data type of aux field is not known")]
97 BamAuxUnknownType,
98 #[error("failed to add aux field, tag is already present")]
99 BamAuxTagAlreadyPresent,
100 #[error("updating the aux field for this datatype is not supported")]
101 BamAuxTagUpdatingNotSupported,
102
103 #[error("no base modification tag found for record")]
105 BamBaseModificationTagNotFound,
106 #[error("no base modification with the specified code found in record")]
107 BamBaseModificationTypeNotFound,
108 #[error("base modification iteration failed")]
109 BamBaseModificationIterationFailed,
110 #[error("base modification found too many modifications")]
111 BamBaseModificationTooManyMods,
112
113 #[error("error allocating internal data structure for BCF/VCF reader (out of memory?)")]
115 BcfAllocationError,
116 #[error("failed to open BCF/VCF from {target:?}")]
117 BcfOpen { target: String },
118 #[error("invalid record in BCF/VCF file")]
119 BcfInvalidRecord,
120 #[error("tag {tag} undefined in BCF/VCF header")]
121 BcfUndefinedTag { tag: String },
122 #[error("unexpected type for tag {tag} in BCF/VCF file")]
123 BcfUnexpectedType { tag: String },
124 #[error("tag {tag} missing from record {record} in BCF/VCF file")]
125 BcfMissingTag { tag: String, record: String },
126 #[error("error setting tag {tag} in BCF/VCF record (out of memory?)")]
127 BcfSetTag { tag: String },
128 #[error("ID {rid} not found in BCF/VCF header")]
129 BcfUnknownRID { rid: u32 },
130 #[error("contig {contig} not found in BCF/VCF header")]
131 BcfUnknownContig { contig: String },
132 #[error("ID {id} not found in BCF/VCF header")]
133 BcfUnknownID { id: String },
134 #[error("sample {name} not found in BCF/VCF header")]
135 BcfUnknownSample { name: String },
136 #[error("duplicate sample names given for subsetting BCF/VCF")]
137 BcfDuplicateSampleNames,
138 #[error("failed to set values in BCF/VCF record (out of memory?)")]
139 BcfSetValues,
140 #[error("failed to remove alleles in BCF/VCF record")]
141 BcfRemoveAlleles,
142 #[error("failed to render BCF record as string")]
143 BcfToString,
144 #[error("failed to translate BCF/VCF record")]
145 BcfTranslate,
146
147 #[error("invalid compression level {level}")]
148 BgzfInvalidCompressionLevel { level: i8 },
149 #[error("failed setting hts reading options")]
150 HtsSetOpt,
151 #[error("failed calculating slow index statistics")]
152 SlowIdxStats,
153 #[error("invalid tid {tid}")]
154 InvalidTid { tid: i32 },
155 #[error("No sequences in the reference")]
156 NoSequencesInReference,
157}