bgzip/
error.rs

1use thiserror::Error;
2
3/// A BGZF error.
4#[derive(Debug, Error)]
5pub enum BGZFError {
6    /// Failed to parse header
7    #[error("Failed to parse header at position: {position}")]
8    HeaderParseError { position: u64 },
9    /// Not tabix format
10    #[error("not tabix format")]
11    NotTabix,
12    /// Not BGZF format
13    #[error("not BGZF format")]
14    NotBGZF,
15    /// Not gzip format
16    #[error("not gzip format")]
17    NotGzip,
18    /// Too larget compress unit. A compress unit must be smaller than 64k bytes.
19    #[error("Too large compress unit")]
20    TooLargeCompressUnit,
21    /// I/O Error
22    #[error("I/O Error: {0}")]
23    IoError(#[from] std::io::Error),
24    /// UTF-8 Error
25    #[error("Utf8 Error: {0}")]
26    Utf8Error(#[from] std::str::Utf8Error),
27    /// Failed to convert native path to UTF-8
28    #[error("Failed to convert native path to UTF-8")]
29    PathConvertionError,
30    /// Deflate compresssion error
31    #[error("Compression Error: {0}")]
32    CompressionError(#[from] crate::deflate::CompressError),
33    /// Inflate decompression error
34    #[error("Decompression Error: {0}")]
35    DecompressionError(#[from] crate::deflate::DecompressError),
36    /// Invalid compression level
37    #[error("Invalid Compression Level")]
38    InvalidCompressionLevel,
39    /// Other error
40    #[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}