1use thiserror::Error;
2
3#[derive(Debug, Error)]
5pub enum BGZFError {
6 #[error("Failed to parse header at position: {position}")]
8 HeaderParseError { position: u64 },
9 #[error("not tabix format")]
11 NotTabix,
12 #[error("not BGZF format")]
14 NotBGZF,
15 #[error("not gzip format")]
17 NotGzip,
18 #[error("Too large compress unit")]
20 TooLargeCompressUnit,
21 #[error("I/O Error: {0}")]
23 IoError(#[from] std::io::Error),
24 #[error("Utf8 Error: {0}")]
26 Utf8Error(#[from] std::str::Utf8Error),
27 #[error("Failed to convert native path to UTF-8")]
29 PathConvertionError,
30 #[error("Compression Error: {0}")]
32 CompressionError(#[from] crate::deflate::CompressError),
33 #[error("Decompression Error: {0}")]
35 DecompressionError(#[from] crate::deflate::DecompressError),
36 #[error("Invalid Compression Level")]
38 InvalidCompressionLevel,
39 #[error("Error: {0}")]
41 Other(&'static str),
42}
43
44impl Into<std::io::Error> for BGZFError {
45 fn into(self) -> std::io::Error {
46 match self {
47 BGZFError::IoError(e) => e,
48 other => std::io::Error::new(std::io::ErrorKind::Other, other),
49 }
50 }
51}
52
53impl BGZFError {
54 pub fn into_io_error(self) -> std::io::Error {
55 self.into()
56 }
57}