Skip to main content

mila/
errors.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum CompressionError {
5    #[error("Input is not compressed using {0}.")]
6    InvalidInput(String)
7}
8
9#[derive(Error, Debug)]
10pub enum EncodedStringsError {
11    #[error("Fell out of buffer while reading a null-terminated string.")]
12    UnterminatedString,
13
14    #[error("Failed to encode string {0} with encoding {1}.")]
15    EncodingFailed(String, String),
16
17    #[error("Unable to decode {0} string.")]
18    DecodingFailed(String),
19
20    #[error(transparent)]
21    IOError(#[from] std::io::Error),
22}
23
24#[derive(Error, Debug)]
25pub enum ArchiveError {
26    #[error("The archive size specified in the header is incorrect.")]
27    SizeMismatch,
28
29    #[error("The archive is not big enough to support the size required by the header.")]
30    ArchiveTooSmall,
31
32    #[error("Out of bounds address '0x{0:x}' with archive of size '0x{1:x}'.")]
33    OutOfBoundsAddress(usize, usize),
34
35    #[error("Unaligned value '{0}' should be aligned to {1} bytes.")]
36    UnalignedValue(usize, usize),
37
38    #[error("Index '{1}' is out of bounds for label bucket of size '{0}'.")]
39    LabelIndexOutOfBounds(usize, usize),
40
41    #[error(transparent)]
42    IOError(#[from] std::io::Error),
43
44    #[error(transparent)]
45    EncodingStringsError(#[from] EncodedStringsError),
46}
47
48
49#[derive(Error, Debug)]
50pub enum LocalizationError {
51    #[error("Unsupported language.")]
52    UnsupportedLanguage,
53
54    #[error("Expected parent in path '{0}'.")]
55    MissingParent(std::path::PathBuf),
56
57    #[error("Expected file name in path '{0}'.")]
58    MissingFileName(std::path::PathBuf),
59
60    #[error(transparent)]
61    IOError(#[from] std::io::Error),
62}
63
64#[derive(Error, Debug)]
65pub enum LayeredFilesystemError {
66    #[error("Cannot create a filesystem with no layers.")]
67    NoLayers,
68
69    #[error("Filesystem contains no writeable layers.")]
70    NoWriteableLayers,
71
72    #[error("File '{0}' does not exist.")]
73    FileNotFound(String),
74
75    #[error("Failed to read file '{0}' due to nested error: {1}")]
76    ReadError(String, String),
77
78    #[error("Failed to write file '{0}' due to nested error: {1}")]
79    WriteError(String, String),
80
81    #[error("Unsupported game.")]
82    UnsupportedGame,
83
84    #[error(transparent)]
85    PatternError(#[from] glob::PatternError),
86
87    #[error(transparent)]
88    LocalizationError(#[from] LocalizationError),
89
90    #[error(transparent)]
91    IOError(#[from] std::io::Error),
92
93    #[error(transparent)]
94    CompressionError(#[from] CompressionError),
95
96    #[error(transparent)]
97    ArchiveError(#[from] ArchiveError),
98
99    #[error(transparent)]
100    TextArchiveError(#[from] TextArchiveError),
101
102    #[error(transparent)]
103    TextureParseError(#[from] TextureParseError),
104
105    #[error(transparent)]
106    ArcError(#[from] ArcError),
107}
108
109#[derive(Error, Debug)]
110pub enum TextArchiveError {
111    #[error("Malformed text archive - message has no key.")]
112    MissingKey,
113
114    #[error(transparent)]
115    ArchiveError(#[from] crate::ArchiveError),
116
117    #[error(transparent)]
118    IOError(#[from] std::io::Error),
119
120    #[error(transparent)]
121    EncodingStringsError(#[from] crate::EncodedStringsError),
122}
123
124#[derive(Error, Debug)]
125pub enum DialogueError {
126    #[error("{0}")]
127    ParseError(String),
128
129    #[error("Unexpected rule.")]
130    BadRule,
131
132    #[error("An undefined error occurred.")]
133    UndefinedError
134}
135
136#[derive(Error, Debug)]
137pub enum TextureDecodeError {
138    #[error("Unsupported format.")]
139    UnsupportedFormat,
140
141    #[error(transparent)]
142    IOError(#[from] std::io::Error),
143}
144
145#[derive(Error, Debug)]
146pub enum TextureParseError {
147    #[error("Invalid magic number.")]
148    BadMagicNumber,
149
150    #[error("Failed to decode text.")]
151    BadText,
152
153    #[error(transparent)]
154    IOError(#[from] std::io::Error),
155
156    #[error(transparent)]
157    TextureDecodeError(#[from] TextureDecodeError),
158}
159
160#[derive(Error, Debug)]
161pub enum ArcError {
162    #[error("Arc entry has no name.")]
163    MissingName,
164
165    #[error("Arc has no count label.")]
166    NoCount,
167
168    #[error("Arc has no info label.")]
169    NoInfo,
170
171    #[error(transparent)]
172    ArchiveError(#[from] ArchiveError),
173}