maple_rs/
error.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum MapleError {
5    #[error("Invalid PE format: {0}")]
6    InvalidPEFormat(String),
7
8    #[error("Memory allocation failed: {0}")]
9    MemoryAllocation(String),
10
11    #[error("Import resolution failed: {0}")]
12    ImportResolution(String),
13
14    #[error("Relocation processing failed: {0}")]
15    RelocationFailed(String),
16
17    #[error("Symbol not found: {0}")]
18    SymbolNotFound(String),
19
20    #[error("Execution failed: {0}")]
21    ExecutionFailed(String),
22
23    #[error("Platform not supported: {0}")]
24    PlatformNotSupported(String),
25
26    #[error("IO error: {0}")]
27    Io(#[from] std::io::Error),
28
29    #[cfg(windows)]
30    #[error("Windows API error: {0}")]
31    WindowsApi(u32),
32}
33
34impl PartialEq for MapleError {
35    fn eq(&self, other: &Self) -> bool {
36        match (self, other) {
37            (MapleError::InvalidPEFormat(a), MapleError::InvalidPEFormat(b)) => a == b,
38            (MapleError::MemoryAllocation(a), MapleError::MemoryAllocation(b)) => a == b,
39            (MapleError::ImportResolution(a), MapleError::ImportResolution(b)) => a == b,
40            (MapleError::RelocationFailed(a), MapleError::RelocationFailed(b)) => a == b,
41            (MapleError::SymbolNotFound(a), MapleError::SymbolNotFound(b)) => a == b,
42            (MapleError::ExecutionFailed(a), MapleError::ExecutionFailed(b)) => a == b,
43            (MapleError::PlatformNotSupported(a), MapleError::PlatformNotSupported(b)) => a == b,
44            (MapleError::Io(a), MapleError::Io(b)) => a.kind() == b.kind(),
45            #[cfg(windows)]
46            (MapleError::WindowsApi(a), MapleError::WindowsApi(b)) => a == b,
47            _ => false,
48        }
49    }
50}