structured_asic/error.rs
1//! Container processing failures, distinct from readable negative facts.
2
3use structured_asn1::{Span, memory::MemoryError, range::InputError};
4
5/// Original-source processing result without erasing its source error type.
6pub type SourceResult<T, S> = Result<T, Error<<S as structured_asn1::range::RangeSource>::Error>>;
7
8/// Structural ambiguity or syntax that prevents an original member census.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum Syntax {
11 /// No complete end-of-directory record reaches the original EOF.
12 End,
13 /// Two complete directory interpretations reach the same original EOF.
14 AmbiguousDirectory,
15 /// Directory count, extent, record or ZIP64 field is inconsistent.
16 Directory,
17 /// A variable record or checked arithmetic exceeds its original enclosure.
18 Bounds,
19 /// A required local file header or descriptor cannot be interpreted.
20 Local,
21}
22
23/// A configured cumulative mechanism allowance was exhausted.
24#[derive(Debug, Clone, Copy, PartialEq, Eq)]
25pub enum Limit {
26 /// Original member catalogue admissions.
27 Entries,
28 /// Cumulative decoded output, including failed envelopes.
29 Decoded,
30}
31
32/// Processing refused before a successful complete result could be returned.
33#[derive(Debug)]
34pub enum Error<E> {
35 /// Original acquisition, snapshot or current/source execution refusal.
36 Input(InputError<E>),
37 /// Current execution or actual-capacity refusal before work.
38 Resource {
39 /// Physical original enclosure of the attempted operation.
40 range: Span,
41 /// Unchanged refusal cause.
42 cause: MemoryError,
43 },
44 /// A cumulative mechanism allowance refused the next operation.
45 Limit {
46 /// Physical original enclosure.
47 range: Span,
48 /// Exhausted allowance.
49 kind: Limit,
50 },
51 /// No unambiguous structural reading is available.
52 Syntax {
53 /// Physical original enclosure.
54 range: Span,
55 /// Original structural cause.
56 kind: Syntax,
57 },
58 /// The operation requires an unavailable ZIP capability.
59 Unsupported {
60 /// Physical original enclosure.
61 range: Span,
62 /// Exact unavailable capability.
63 kind: Unsupported,
64 },
65 /// A member, receipt or input belongs to another original archive view.
66 Foreign {
67 /// Actual attempted enclosure, without an invented inner position.
68 range: Span,
69 },
70}
71
72/// Unsupported capabilities never masquerade as successful empty content.
73#[derive(Debug, Clone, Copy, PartialEq, Eq)]
74pub enum Unsupported {
75 /// Multi-volume source acquisition is outside the single-source contract.
76 Volumes,
77 /// The directory or member is encrypted.
78 Encryption,
79 /// Exact unimplemented compression method.
80 Compression(u16),
81 /// Central-directory compression/encryption profile.
82 DirectoryVersion(u16),
83}
84
85impl<E> From<InputError<E>> for Error<E> {
86 fn from(cause: InputError<E>) -> Self {
87 Self::Input(cause)
88 }
89}
90
91pub(crate) fn syntax<E>(range: Span, kind: Syntax) -> Error<E> {
92 Error::Syntax { range, kind }
93}
94
95pub(crate) fn resource<E>(range: Span, cause: MemoryError) -> Error<E> {
96 Error::Resource { range, cause }
97}