dig_message/error.rs
1//! The dig-message error taxonomy — stable, catalogued variants a scripted client can key off (§6.2).
2//! WU1 owns the encoding/framing/compression failures; the seal/signature/replay variants arrive with
3//! WU2/WU4.
4
5use thiserror::Error;
6
7/// Every fail-cleanly outcome of encoding, framing, or (de)compressing a dig-message (SPEC §1, §1.1,
8/// §2). A receiver MUST reject — never panic — on any of these.
9#[derive(Debug, Error, PartialEq, Eq)]
10pub enum MessageError {
11 /// The on-wire frame exceeds [`crate::MAX_ENVELOPE_BYTES`] (SPEC §1).
12 #[error("envelope is {size} bytes, exceeds the {max}-byte cap")]
13 EnvelopeTooLarge { size: usize, max: usize },
14
15 /// The frame ended before a complete envelope could be decoded (SPEC §1).
16 #[error("truncated envelope: {0}")]
17 Truncated(String),
18
19 /// The envelope declares a version this reader does not support (SPEC §2 field 1).
20 #[error("unsupported envelope version {0}")]
21 UnsupportedVersion(u8),
22
23 /// The compression algorithm id is not recognized (SPEC §1.1). Never mis-decode with a wrong codec.
24 #[error("unsupported compression id {0}")]
25 UnsupportedCompression(u8),
26
27 /// The declared uncompressed length exceeds the bomb-guard cap (SPEC §1.1).
28 #[error("declared uncompressed length {declared} exceeds the {max}-byte cap")]
29 DecompressionBomb { declared: usize, max: usize },
30
31 /// The decoded output length did not match the declared `uncompressed_len` (SPEC §1.1).
32 #[error("decompressed length mismatch: expected {expected}, got {actual}")]
33 DecompressedLengthMismatch { expected: usize, actual: usize },
34
35 /// A payload's uncompressed length does not fit the `u32` wire field (SPEC §5.2).
36 #[error("payload is {0} bytes, exceeds the u32 uncompressed_len field")]
37 PayloadTooLarge(usize),
38
39 /// A Streamable (de)serialization or codec-level failure with the underlying detail (SPEC §1).
40 #[error("codec error: {0}")]
41 Codec(String),
42}
43
44/// The crate result alias.
45pub type Result<T> = std::result::Result<T, MessageError>;