1use crate::base::VInt64;
2
3#[derive(Debug, thiserror::Error)]
5#[non_exhaustive]
6pub enum Error {
7 #[error("I/O error: {0}")]
9 Io(#[from] std::io::Error),
10
11 #[error("Invalid variable-length integer encoding, 8 leading zeros found...")]
13 InvalidVInt,
14
15 #[error("Attempted to read past the end of the buffer")]
17 TryGetError(#[from] bytes::TryGetError),
18
19 #[error("Element body over decode, ID: {0}")]
21 OverDecode(VInt64),
22
23 #[error("Short read: not all bytes were consumed")]
25 ShortRead,
26
27 #[error("Element body under decode, ID: {0}")]
29 UnderDecode(VInt64),
30
31 #[error("Missing element, ID: {0}")]
33 MissingElement(VInt64),
34
35 #[error("Duplicate element {id} in master element {parent}")]
37 DuplicateElement {
38 id: VInt64,
40 parent: VInt64,
42 },
43
44 #[error("Element body size is unknown, ID: {0}")]
46 ElementBodySizeUnknown(VInt64),
47
48 #[error("Malformed lacing data")]
50 MalformedLacingData,
51}
52
53impl Error {
54 #[inline]
56 pub fn try_get_error(requested: usize, available: usize) -> Self {
57 Error::TryGetError(bytes::TryGetError {
58 requested,
59 available,
60 })
61 }
62}
63
64pub type Result<T> = std::result::Result<T, Error>;