1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// SPDX-License-Identifier: Apache-2.0
use crate::{pixel::PixelFormat, sample::SampleType};
/// Buffer validation and copy errors.
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum BufferError {
/// Destination buffer is too small for the requested output.
#[error("output buffer too small: required {required} bytes, have {have}")]
OutputTooSmall {
/// Required destination length in bytes.
required: usize,
/// Actual destination length in bytes.
have: usize,
},
/// Source buffer is too small for the requested copy/decode.
#[error("input buffer too small: required {required} bytes, have {have}")]
InputTooSmall {
/// Required source length in bytes.
required: usize,
/// Actual source length in bytes.
have: usize,
},
/// A byte-count computation overflowed.
#[error("buffer size overflow while computing {what}")]
SizeOverflow {
/// Name of the size being computed.
what: &'static str,
},
/// A requested allocation exceeds the configured safety cap.
#[error("{what} allocation too large: requested {requested} bytes, cap {cap}")]
AllocationTooLarge {
/// Requested byte count.
requested: usize,
/// Configured byte cap.
cap: usize,
/// Name of the allocation being checked.
what: &'static str,
},
/// Output stride cannot hold one decoded row.
#[error("stride {stride} is smaller than row width {row_bytes}")]
StrideTooSmall {
/// Required row width in bytes.
row_bytes: usize,
/// Supplied stride in bytes.
stride: usize,
},
/// Output stride does not meet backend alignment requirements.
#[error("stride {stride} is not aligned to {align}")]
StrideNotAligned {
/// Supplied stride in bytes.
stride: usize,
/// Required byte alignment.
align: usize,
},
/// Requested pixel format uses a different sample width than the row type.
#[error("pixel format {fmt:?} does not match sample type {sample_type:?}")]
SampleTypeMismatch {
/// Requested output pixel format.
fmt: PixelFormat,
/// Sample type accepted by the current sink or buffer.
sample_type: SampleType,
},
}
/// Generic malformed or truncated input errors.
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum InputError {
/// Input ended before a required fixed-size read.
#[error("input too short: need {need} bytes, have {have}")]
TooShort {
/// Required byte count.
need: usize,
/// Available byte count.
have: usize,
},
/// Input ended while reading a named segment.
#[error("input truncated at offset {offset} while reading {segment}")]
TruncatedAt {
/// Byte offset where truncation was detected.
offset: usize,
/// Name of the segment being read.
segment: &'static str,
},
}
/// Error for a valid request that is not implemented yet.
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
#[error("not yet implemented: {what}")]
pub struct NotImplemented {
/// Feature or path that is not implemented.
pub what: &'static str,
}
/// Error for input or options unsupported by the current codec.
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
#[error("unsupported: {what}")]
pub struct Unsupported {
/// Unsupported feature or option.
pub what: &'static str,
}
/// Shared error classification used by facade traits.
pub trait CodecError: core::error::Error + Send + Sync + 'static {
/// True when the error indicates truncated input.
fn is_truncated(&self) -> bool;
/// True when the error indicates an unimplemented supported surface.
fn is_not_implemented(&self) -> bool;
/// True when the error indicates unsupported input or options.
fn is_unsupported(&self) -> bool;
/// True when the error indicates caller buffer sizing or layout problems.
fn is_buffer_error(&self) -> bool;
}