mizu_core/cartridge/
error.rs1use super::mappers::MapperType;
2use std::convert::From;
3use std::fmt::Debug;
4use std::io::{Error as ioError, ErrorKind as ioErrorKind};
5
6#[derive(thiserror::Error, Debug)]
8pub enum CartridgeError {
9 #[error("File error: {0}")]
11 FileError(ioError),
12 #[error("The file ends with an invalid extension, should end with '.gb' or '.gbc'")]
14 ExtensionError,
15 #[error("The rom file does not contain a valid Nintendo logo data at 0x104")]
17 InvalidNintendoLogo,
18 #[error("The game title contain invalid UTF-8 characters")]
20 InvalidGameTitle,
21 #[error("Rom file contain unsupported cartridge type")]
23 InvalidCartridgeType,
24 #[error("The rom size index {0} is invalid")]
26 InvalidRomSizeIndex(u8),
27 #[error("The ram size index {0} is invalid")]
29 InvalidRamSizeIndex(u8),
30 #[error("The file size does not match the rom size {0} bytes indicated inside the header")]
32 InvalidRomSize(usize),
33 #[error("The cartridge type suggest the cartridge has ram, but it is not present")]
35 RamNotPresentError,
36 #[error("The cartridge type suggest the cartridge does not have ram, but it is present")]
38 NotNeededRamPresentError,
39 #[error("The header of the cartridge checksum {got} does not match the expected {expected}")]
41 InvalidChecksum { expected: u8, got: u8 },
42 #[error("The mapper {0:?} is not yet implemented")]
44 MapperNotImplemented(MapperType),
45}
46
47impl From<ioError> for CartridgeError {
48 fn from(from: ioError) -> Self {
49 Self::FileError(from)
50 }
51}
52
53#[derive(thiserror::Error, Debug)]
54pub enum SramError {
55 #[error("Could not load cartridge save file")]
56 NoSramFileFound,
57 #[error("There is a conflict in the size of SRAM save file in the Cartridge header and the file in disk")]
58 SramFileSizeDoesNotMatch,
59 #[error("Could not save cartridge save file")]
60 FailedToSaveSramFile,
61 #[error("Unknown error occured while trying to save/load cartridge save file")]
62 Others,
63}
64
65impl From<ioError> for SramError {
66 fn from(from: ioError) -> Self {
67 match from.kind() {
68 ioErrorKind::NotFound => Self::NoSramFileFound,
69 ioErrorKind::PermissionDenied => Self::FailedToSaveSramFile,
70 _ => Self::Others,
71 }
72 }
73}