Skip to main content

crabka_compression/
error.rs

1//! Errors returned by `compress` and `decompress`.
2
3use thiserror::Error;
4
5/// Errors that can occur during compression or decompression.
6#[derive(Debug, Error)]
7#[non_exhaustive]
8pub enum CompressionError {
9    /// The requested codec was not enabled at compile time. The codec name
10    /// is one of `"gzip"`, `"snappy"`, `"lz4"`, `"zstd"`.
11    #[error("compression feature `{0}` not enabled at compile time")]
12    FeatureDisabled(&'static str),
13
14    /// The compressed payload could not be parsed (truncated input, bad
15    /// framing, invalid checksum, etc.).
16    #[error("invalid compressed data: {0}")]
17    InvalidData(String),
18
19    /// I/O error from one of the codec libraries.
20    #[error("I/O error: {0}")]
21    Io(#[from] std::io::Error),
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27    use assert2::assert;
28
29    #[test]
30    fn feature_disabled_display() {
31        let e = CompressionError::FeatureDisabled("snappy");
32        assert!(e.to_string() == "compression feature `snappy` not enabled at compile time");
33    }
34}