diff --git a/crates/compression/Cargo.toml b/crates/compression/Cargo.toml index 9193f7dd..64b70cea 100644 --- a/crates/compression/Cargo.toml +++ b/crates/compression/Cargo.toml @@ -15,6 +15,7 @@ criterion = { workspace = true } hash = { workspace = true } log = { workspace = true } sl-std = { workspace = true } +error-derive = { workspace = true } [[bench]] name = "brotli" diff --git a/crates/compression/src/deflate.rs b/crates/compression/src/deflate.rs index 3b77e4c2..be8b8480 100644 --- a/crates/compression/src/deflate.rs +++ b/crates/compression/src/deflate.rs @@ -1,25 +1,35 @@ use crate::huffman::HuffmanTree; +use error_derive::Error; use sl_std::bitreader::{self, BitReader}; use std::cmp::{min, Ordering}; -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, Error)] pub enum Error { + #[msg = "invalid compression scheme"] InvalidCompressionScheme, + + #[msg = "reserved compression scheme"] ReservedCompressionScheme, + + #[msg = "unexpected end of file"] UnexpectedEOF, + + #[msg = "symbol not found"] SymbolNotFound, + + #[msg = "run length encoding leading repeat value"] RLELeadingRepeatValue, + + #[msg = "run length encoding exceeds expected value"] RLEExceedsExpectedLength, + + #[msg = "invalid uncompressed block length"] InvalidUncompressedBlockLength, - BitReader(bitreader::Error), -} -impl From for Error { - fn from(value: bitreader::Error) -> Self { - Self::BitReader(value) - } + #[msg = "failed to read bits"] + BitReader(bitreader::Error), } #[derive(Clone, Copy, Debug)]