Skip to main content

uorustlibs/
error.rs

1//! Shared error types
2use thiserror::Error;
3
4pub const MEMWRITER_ERROR: &str = "MemWriter unexpectedly failed";
5
6/// Errors that occur when reading muls
7#[derive(Error, Debug)]
8pub enum MulReaderError {
9    #[error("IO Error: {0}")]
10    Io(#[from] std::io::Error),
11    #[error("Trying to read out of bounds index {0}")]
12    IndexOutOfBounds(u32),
13    #[error("Trying to read out of bounds record {index}, with a start of {offset}")]
14    OffsetOutOfBounds { index: u32, offset: u32 },
15    #[error("Got a record of size {found}, expected {expected}")]
16    UnexpectedSize { found: u32, expected: u32 },
17    #[error("Failed to parse: {0}")]
18    FailedParse(String),
19    #[error("Coordinates {x}, {y} are out of bounds")]
20    CoordinatesOutOfBounds { x: u32, y: u32 },
21}
22
23/// Errors that occur when writing muls
24#[derive(Error, Debug)]
25pub enum MulWriterError {
26    #[error("IO Error: {0}")]
27    Io(#[from] std::io::Error),
28}
29
30pub type MulReaderResult<T> = std::result::Result<T, MulReaderError>;
31pub type MulWriterResult<T> = std::result::Result<T, MulWriterError>;
32
33/// Errors that occur when trying to create Image types from Mul data
34#[derive(Error, Debug)]
35pub enum ToImageError {
36    #[error("Pixel {x}, {y} is out of bounds")]
37    PixelOutOfBounds { x: i64, y: i64 },
38    #[error("Invalid image size of {x}, {y}")]
39    InvalidImageSize { x: u32, y: u32 },
40}