Skip to main content

android_abx/
error.rs

1/// The error type for every fallible operation in this crate.
2#[derive(Debug, thiserror::Error)]
3pub enum AbxError {
4    /// The input does not start with [`MAGIC`](crate::MAGIC).
5    #[error("invalid magic header: expected {expected:?}, got {actual:?}")]
6    InvalidMagic {
7        /// Expected magic.
8        expected: [u8; 4],
9        /// Magic found.
10        actual: [u8; 4],
11    },
12    /// The input ended in the middle of a token. The string names what was being read.
13    #[error("unexpected end of input while reading {0}")]
14    UnexpectedEof(&'static str),
15    /// An interned-string reference points past the strings read so far.
16    #[error("invalid interned string index {0}")]
17    BadInternedIndex(u16),
18    /// String is not valid UTF-8.
19    #[error("invalid UTF-8 in string")]
20    InvalidUtf8,
21    /// An attribute has an unknown type nibble.
22    #[error("unknown attribute type 0x{0:02X}")]
23    UnknownAttributeType(u8),
24    /// A token has an unknown command nibble.
25    #[error("unknown command 0x{0:02X}")]
26    UnknownCommand(u8),
27    /// A string or byte value is longer than the 65,535 bytes the format allows.
28    #[error("value too long: {len} bytes exceeds maximum of {max}")]
29    ValueTooLong {
30        /// Actual length in bytes.
31        len: usize,
32        /// Maximum length (`u16::MAX`).
33        max: usize,
34    },
35    /// Low-level parse failure.
36    #[error("nom parse error: {0}")]
37    Nom(String),
38    /// Reading or writing failed.
39    #[error("I/O error: {0}")]
40    Io(#[from] std::io::Error),
41    /// Deserializing into a serde type failed.
42    #[error("deserialization error: {0}")]
43    Deserialization(String),
44    /// The XML text passed to `xml_to_abx` is malformed.
45    #[error("XML parse error: {0}")]
46    Xml(String),
47}
48
49/// A [`Result`](std::result::Result) with [`AbxError`] as the error type.
50pub type Result<T> = std::result::Result<T, AbxError>;