rusty_dex/error.rs
1//! Collection of error types for DEX files parsing
2//!
3//! We rely on `thiserror` for the heavy lifting
4
5use thiserror::Error;
6
7#[derive(Error, Debug)]
8/// All errors that can be returned by the parser
9pub enum DexError {
10 /// The checksum of the header does not match the one in the DEX header
11 #[error("computed checksum does not match one in header")]
12 InvalidChecksumError,
13 /// The header of the file is too short to be a valid DEX header
14 #[error("DEX header too short")]
15 DexHeaderTooShortError,
16 /// The endianness tag of the header is invalid
17 #[error("invalid endianness tag")]
18 InvalidEndianessTag,
19 /// The stream ended abruptly
20 #[error("no data left to read")]
21 NoDataLeftError,
22 /// The unsigned LEB128 value has more than 5 bytes
23 #[error("too many bytes in unsigned LEB128 value")]
24 InvalidUleb128Value,
25 /// The signed LEB128 value has more than 5 bytes
26 #[error("too many bytes in unsigned LEB128p1 value")]
27 InvalidUleb128p1Value,
28 /// The unsigned LEB128p1 value has more than 5 bytes
29 #[error("too many bytes in signed LEB128 value")]
30 InvalidSleb128Value,
31 /// Attempted to move the cursor after the end of the stream
32 #[error("cannot move reader to requested offset")]
33 SeekError(#[from] std::io::Error),
34 /// Requested type index is not in the list of types
35 #[error("cannot find element in types list")]
36 InvalidTypeIdx,
37 /// Requested string index is not in the list of strings
38 #[error("cannot find element in strings list")]
39 InvalidStringIdx,
40 /// Requested field index is not in the list of fields
41 #[error("cannot find element in fields list")]
42 InvalidFieldIdx,
43 /// Requested method index is not in the list of methods
44 #[error("cannot find element in methods list")]
45 InvalidMethodIdx,
46 /// Encountered an invalid or unused opcode
47 #[error("cannot parse instruction opcode")]
48 InvalidOpCode,
49}