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
use thiserror::Error;
/// Alias for a [`Result`][core::result::Result] with the error type [`ManifestError`].
pub type Result<T> = core::result::Result<T, ManifestError>;
/// This enum represents all possible errors that may occur when parsing a file.
#[derive(Error, Debug)]
pub enum ManifestError {
/// The error was caused by a failure to seek to a desired offset.
///
/// This error occurs when [`Seek`][std::io::Seek] fails.
#[error("could not seek to desired position, error: {0}")]
SeekError(std::io::Error),
/// The error was caused by invalid magic bytes.
///
/// This error occurs when the first four bytes (magic bytes) do not equal `0x52`, `0x4D`,
/// `0x41` and `0x4E` (or `R`, `M`, `A`, `N` in ascii) respectively.
///
/// Usually caused by providing a file that is not a Riot Manifest file.
#[error("invalid magic bytes (expected: \"0x4E414D52\", was: \"{0:#010x}\")")]
InvalidMagicBytes(u32),
/// The error was caused by invalid major version.
///
/// This error occurs when the major version in the file header doesn't equal 2.
///
/// Should only occur if the manifest format gets a major change or an update, Parser
/// may no longer function if this happens.
///
/// NOTE: The feature `version_error` must be enabled for this error to occur.
#[error("unsupported major version (expected: \"2\", was: \"{0}\")")]
#[cfg(any(feature = "version_error", doc))]
InvalidMajor(u8),
/// The error was caused by invalid minor version.
///
/// This error occurs when the minor version in the file header doesn't equal 0.
///
/// Should only occur if the manifest format gets a minor change or an update. Parser
/// should still be functional if this happens,
///
/// NOTE: The feature `version_error` must be enabled for this error to occur.
#[error("unsupported minor version (expected: \"0\", was: \"{0}\")")]
#[cfg(any(feature = "version_error", doc))]
InvalidMinor(u8),
/// The error was caused by an invalid offset.
///
/// This error occurs when the offset is smaller or larger than the file itself.
///
/// Should never happen for official, Riot-made manifests.
#[error("offset ({0}) is larger than the total file size")]
InvalidOffset(u32),
/// The error was caused by compressed size being too large.
///
/// This error occurs when the compressed size is larger than the file itself.
///
/// Should never happen for official, Riot-made manifests.
#[error("compressed size ({0}) is larger than the total file size")]
CompressedSizeTooLarge(u32),
/// The error was caused by a failure to read or write bytes on an IO stream.
///
/// This error occurs when [`read_exact`][std::io::Read::read_exact], any `read_` method in
/// [`byteorder::ReadBytesExt`], or [`File::open`][std::fs::File::open] fails.
///
/// Usually caused by invalid or inaccessible path or unexpected eof when parsing a header.
#[error("{0}")]
IoError(#[from] std::io::Error),
/// The error was caused by a failure to convert from one number type to another.
///
/// This error occurs when the conversion from or into [`usize`] fails.
///
/// Should never fail on 32-bit (or higher) targets.
#[error("conversion failed, error: {0}")]
ConversionFailure(#[from] std::num::TryFromIntError),
/// The error was caused by a failure to decompress zstd data.
///
/// This error occurs when [`decompress`][zstd::bulk::decompress] fails.
///
/// Should never happen for official, Riot-made manifests.
#[error("{0}")]
ZstdDecompressError(std::io::Error),
/// The error was caused by a failure to parse [`FileEntry`][crate::entries::FileEntry] into
/// [`File`][crate::File].
///
/// This error occurs when either a [`directory_id`](crate::entries::FileEntry::directory_id)
/// or [`parent_id`](crate::entries::DirectoryEntry::parent_id) points to an invalid
/// [`DirectoryEntry`][crate::entries::DirectoryEntry] or when
/// [`chunk_id`](crate::entries::FileEntry::chunk_ids) refers to an invalid
/// [`ChunkEntry`][crate::entries::ChunkEntry].
///
/// Should never happen for official, Riot-made manifests.
#[error("{0}")]
FileParseError(String),
/// The error was caused by an invalid flatbuffer.
///
/// This error occurs when a flatbuffer fails to verify.
///
/// Should never happen for official, Riot-made manifests.
#[error("{0}")]
FlatbufferError(#[from] flatbuffers::InvalidFlatbuffer),
/// The error was caused by a failure to process a [`Request`][reqwest::Request].
///
/// This error occurs when [`Client::send()`](reqwest::RequestBuilder::send) fails.
///
/// Usually occurs when there is no internet connection, or when an invalid bundle url was
/// provided.
#[error("{0}")]
ReqwestError(#[from] reqwest::Error),
}