archive_core/error.rs
1//! Error type for archive peeling and member reading. Fail loud; never silently
2//! truncate, and always name the offending format/cap in the message.
3
4use thiserror::Error;
5
6pub type Result<T> = core::result::Result<T, ArchiveError>;
7
8#[derive(Debug, Error)]
9#[non_exhaustive]
10pub enum ArchiveError {
11 /// A codec decoder failed on the packed stream.
12 #[error("{format} decode failed: {detail}")]
13 Decode {
14 format: &'static str,
15 detail: String,
16 },
17
18 /// The decompressed output exceeded the in-memory cap (bomb guard) — a
19 /// loud failure, never a silent truncation.
20 #[error("decompressed output exceeds the {cap}-byte cap")]
21 TooLarge { cap: u64 },
22
23 /// Parsing an archive's directory / central structure failed.
24 #[error("{format} archive open failed: {detail}")]
25 Open {
26 format: &'static str,
27 detail: String,
28 },
29
30 /// Extracting a single member failed (bad offset, unsupported member codec,
31 /// CRC mismatch, …). The detail carries the backend's own diagnostic.
32 #[error("{format} member read failed: {detail}")]
33 Read {
34 format: &'static str,
35 detail: String,
36 },
37
38 /// A member index was out of range for the archive.
39 #[error("member index {index} out of range ({count} members)")]
40 IndexOutOfRange { index: usize, count: usize },
41
42 /// The recursion peeled past the configured nesting limit (bomb guard). The
43 /// chain names the layer path that tripped it.
44 #[error("nesting depth exceeded the max of {max} at layer chain: {chain}")]
45 DepthExceeded { max: usize, chain: String },
46
47 /// The cumulative number of members across the whole recursion exceeded the
48 /// configured cap (bomb guard).
49 #[error("member count exceeded the max of {max}")]
50 TooManyEntries { max: usize },
51
52 /// The cumulative inflated size across the whole recursion exceeded the cap
53 /// (bomb guard) — tracked across layers, not per layer.
54 #[error("cumulative inflated size exceeded the {cap}-byte cap")]
55 TotalInflatedExceeded { cap: u64 },
56}