|
1 | 1 | use thiserror::Error;
|
2 | 2 |
|
| 3 | +/// Alias for a [`Result`][core::result::Result] with the error type [`ManifestError`]. |
3 | 4 | pub type Result<T> = core::result::Result<T, ManifestError>;
|
4 | 5 |
|
| 6 | +/// This enum represents all possible errors that may occur when parsing a file. |
5 | 7 | #[derive(Error, Debug)]
|
6 | 8 | pub enum ManifestError {
|
| 9 | + /// The error was caused by a failure to seek to a desired offset. |
| 10 | + /// |
| 11 | + /// This error occurs when [`Seek`][std::io::Seek] fails. |
7 | 12 | #[error("Could not seek to desired position. Error: {0}")]
|
8 | 13 | SeekError(std::io::Error),
|
| 14 | + /// The error was caused by invalid magic bytes. |
| 15 | + /// |
| 16 | + /// This error occurs when the first four bytes (magic bytes) do not equal `0x52`, `0x4D`, |
| 17 | + /// `0x41` and `0x4E` (or `R`, `M`, `A`, `N` in ascii) respectively. |
| 18 | + /// |
| 19 | + /// Usually caused by providing a file that is not a Riot Manifest file. |
9 | 20 | #[error("Invalid magic bytes (expected: \"0x4E414D52\", was: \"{0:#010x}\").")]
|
10 | 21 | InvalidMagicBytes(u32),
|
| 22 | + /// The error was caused by invalid major version. |
| 23 | + /// |
| 24 | + /// This error occurs when the major version in the file header doesn't equal 2. |
| 25 | + /// |
| 26 | + /// Should only occur if the manifest format gets a major change or an update, Parser |
| 27 | + /// may no longer function if this happens. |
| 28 | + /// |
| 29 | + /// NOTE: The feature `version_error` must be enabled for this error to occur. |
11 | 30 | #[error("Unsupported major version (expected: \"2\", was: \"{0}\").")]
|
12 | 31 | #[cfg(feature = "version_error")]
|
13 | 32 | InvalidMajor(u8),
|
| 33 | + /// The error was caused by invalid minor version. |
| 34 | + /// |
| 35 | + /// This error occurs when the minor version in the file header doesn't equal 0. |
| 36 | + /// |
| 37 | + /// Should only occur if the manifest format gets a minor change or an update. Parser |
| 38 | + /// should still be functional if this happens, |
| 39 | + /// |
| 40 | + /// NOTE: The feature `version_error` must be enabled for this error to occur. |
14 | 41 | #[error("Unsupported minor version (expected: \"0\", was: \"{0}\").")]
|
15 | 42 | #[cfg(feature = "version_error")]
|
16 | 43 | InvalidMinor(u8),
|
| 44 | + /// The error was caused by an invalid offset. |
| 45 | + /// |
| 46 | + /// This error occurs when the offset is smaller or larger than the file itself. |
| 47 | + /// |
| 48 | + /// Should never happen for official, Riot-made manifests. |
17 | 49 | #[error("Offset ({0}) is larger than the total file size.")]
|
18 | 50 | InvalidOffset(u32),
|
| 51 | + /// The error was caused by compressed size being too large. |
| 52 | + /// |
| 53 | + /// This error occurs when the compressed size is larger than the file itself. |
| 54 | + /// |
| 55 | + /// Should never happen for official, Riot-made manifests. |
19 | 56 | #[error("Compressed size ({0}) is larger than the total file size.")]
|
20 | 57 | CompressedSizeTooLarge(u32),
|
| 58 | + /// The error was caused by a failure to read or write bytes on an IO stream. |
| 59 | + /// |
| 60 | + /// This error occurs when [`read_exact`][std::io::Read::read_exact], any `read_` method in |
| 61 | + /// [`byteorder::ReadBytesExt`], or [`File::open`][std::fs::File::open] fails. |
| 62 | + /// |
| 63 | + /// Usually caused by invalid or inaccessible path or unexpected eof when parsing a header. |
21 | 64 | #[error("{0}")]
|
22 | 65 | IoError(#[from] std::io::Error),
|
| 66 | + /// The error was caused by a failure to convert from one number type to another. |
| 67 | + /// |
| 68 | + /// This error occurs when the conversion from or into [`usize`] fails. |
| 69 | + /// |
| 70 | + /// Should never fail on 32-bit (or higher) targets. |
23 | 71 | #[error("Conversion failed. Error: {0}")]
|
24 | 72 | ConversionFailure(#[from] std::num::TryFromIntError),
|
| 73 | + /// The error was caused by a failure to decompress zstd data. |
| 74 | + /// |
| 75 | + /// This error occurs when [`decompress`][zstd::bulk::decompress] fails. |
| 76 | + /// |
| 77 | + /// Should never happen for official, Riot-made manifests. |
25 | 78 | #[error("{0}")]
|
26 | 79 | ZstdDecompressError(std::io::Error),
|
| 80 | + /// The error was caused by a failure to parse [`FileEntry`][crate::entries::FileEntry] into |
| 81 | + /// [`File`][crate::File]. |
| 82 | + /// |
| 83 | + /// This error occurs when either a [`directory_id`](crate::entries::FileEntry::directory_id) |
| 84 | + /// or [`parent_id`](crate::entries::DirectoryEntry::parent_id) points to an invalid |
| 85 | + /// [`DirectoryEntry`][crate::entries::DirectoryEntry] or when |
| 86 | + /// [`chunk_id`](crate::entries::FileEntry::chunk_ids) refers to an invalid |
| 87 | + /// [`ChunkEntry`][crate::entries::ChunkEntry]. |
| 88 | + /// |
| 89 | + /// Should never happen for official, Riot-made manifests. |
27 | 90 | #[error("{0}")]
|
28 | 91 | FileParseError(String),
|
| 92 | + /// The error was caused by an invalid flatbuffer. |
| 93 | + /// |
| 94 | + /// This error occurs when a flatbuffer fails to verify. |
| 95 | + /// |
| 96 | + /// Should never happen for official, Riot-made manifests. |
29 | 97 | #[error("{0}")]
|
30 | 98 | FlatbufferError(#[from] flatbuffers::InvalidFlatbuffer),
|
31 | 99 | }
|
0 commit comments