bcp_encoder/error.rs
1use bcp_wire::WireError;
2
3/// Errors specific to zstd compression and decompression.
4///
5/// These are surfaced when per-block or whole-payload compression
6/// is enabled and the zstd codec encounters an issue, or when
7/// decompressed output exceeds safety limits.
8///
9/// ```text
10/// CompressionError
11/// ├── CompressFailed ← zstd encoder returned an error
12/// ├── DecompressFailed ← zstd decoder returned an error
13/// └── DecompressionBomb ← decompressed size exceeds safety limit
14/// ```
15#[derive(Debug, thiserror::Error)]
16pub enum CompressionError {
17 #[error("zstd compression failed: {0}")]
18 CompressFailed(String),
19
20 #[error("zstd decompression failed: {0}")]
21 DecompressFailed(String),
22
23 #[error("decompressed size {actual} exceeds limit {limit}")]
24 DecompressionBomb { actual: usize, limit: usize },
25}
26
27/// Errors that can occur during BCP payload encoding.
28///
29/// The encoder validates structural constraints (non-empty payload,
30/// block size limits, summary targeting) and propagates lower-level
31/// wire, I/O, and compression errors from the serialization layer.
32///
33/// Error hierarchy:
34///
35/// ```text
36/// EncodeError
37/// ├── EmptyPayload ← no blocks were added before .encode()
38/// ├── BlockTooLarge ← single block body exceeds size limit
39/// ├── NoBlockTarget ← modifier called with no preceding block
40/// ├── MissingContentStore ← content addressing enabled without a store
41/// ├── Compression(…) ← from zstd compress/decompress
42/// ├── Wire(WireError) ← from bcp-wire serialization
43/// └── Io(std::io::Error) ← from underlying I/O writes
44/// ```
45#[derive(Debug, thiserror::Error)]
46pub enum EncodeError {
47 #[error("no blocks have been added to the encoder")]
48 EmptyPayload,
49
50 #[error("block body exceeds maximum size ({size} bytes, limit {limit})")]
51 BlockTooLarge { size: usize, limit: usize },
52
53 #[error("{method} called but no blocks have been added yet")]
54 NoBlockTarget { method: &'static str },
55
56 #[error("content addressing requires a content store (call set_content_store first)")]
57 MissingContentStore,
58
59 #[error(transparent)]
60 Compression(#[from] CompressionError),
61
62 #[error(transparent)]
63 Wire(#[from] WireError),
64
65 #[error(transparent)]
66 Io(#[from] std::io::Error),
67}