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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//! Error types for the hypercutter library.
use std::path::PathBuf;
/// Result alias for the library.
pub type Result<T> = std::result::Result<T, Error>;
/// Errors that can occur when extracting data from a Pokemon ROM.
#[derive(thiserror::Error, Debug)]
#[non_exhaustive]
pub enum Error {
/// The ROM is too small to contain a valid header.
#[error("ROM too small: {size} bytes, need at least {needed}")]
RomTooSmall {
/// Number of bytes in the input.
size: usize,
/// Minimum bytes required for a valid header.
needed: usize,
},
/// The game code at the expected offset does not match a supported game.
#[error("invalid game code: {code:?}")]
InvalidGameCode {
/// The unrecognized 4-byte game code.
code: [u8; 4],
},
/// The given game name does not match any known game.
#[error("unknown game: {name}")]
UnknownGame {
/// The supplied game name.
name: String,
},
/// A required symbol was not present in the .sym file.
#[error("symbol {name:?} not found in .sym file")]
SymbolNotFound {
/// The missing symbol name.
name: &'static str,
},
/// A symbol line could not be parsed.
#[error("malformed symbol line: {detail}")]
MalformedSymbol {
/// Description of what made the line unparseable.
detail: &'static str,
},
/// A ROM address fell outside the loaded bytes.
#[error("offset 0x{offset:#x} out of range (ROM size 0x{size:#x})")]
OutOfRange {
/// The address that was out of range.
offset: u32,
/// Total size of the loaded ROM in bytes.
size: u32,
},
/// The LZSS header byte was not 0x10 or 0x11.
#[error("invalid LZSS magic byte: 0x{magic:02x}")]
InvalidLzssMagic {
/// The unexpected magic byte.
magic: u8,
},
/// LZSS decompression failed.
#[error("LZSS decompression failed: {message}")]
Decompression {
/// Description of the failure.
message: String,
},
/// The given tileset name was not found.
#[error("unknown tileset: {0}")]
UnknownTileset(#[doc = "The supplied tileset name."] String),
/// The given species id was outside the known range.
#[error("unknown species id: {0}")]
UnknownSpecies(#[doc = "The supplied species id."] u16),
/// An I/O error occurred while reading or writing.
#[error("I/O error at {path}")]
Io {
/// Path of the file involved in the failed I/O.
path: PathBuf,
/// The underlying I/O error.
#[source]
source: std::io::Error,
},
/// A PNG encoding error.
#[error("PNG encoding error: {message}")]
Png {
/// Description of the failure.
message: String,
},
}
impl From<std::io::Error> for Error {
fn from(source: std::io::Error) -> Self {
Self::Io {
path: PathBuf::new(),
source,
}
}
}
impl From<png::EncodingError> for Error {
fn from(source: png::EncodingError) -> Self {
Self::Png {
message: source.to_string(),
}
}
}
impl From<binrw::Error> for Error {
fn from(source: binrw::Error) -> Self {
Self::Io {
path: std::path::PathBuf::from("<binrw>"),
source: std::io::Error::other(source.to_string()),
}
}
}