add structured error handling with thiserror

This commit is contained in:
Adir Shitrit
2025-11-08 11:07:48 +02:00
parent 1aa6f828cf
commit c7ae466c05
2 changed files with 29 additions and 0 deletions

27
ghost-core/src/error.rs Normal file
View File

@@ -0,0 +1,27 @@
use thiserror::Error;
#[derive(Error, Debug)]
pub enum GhostError {
#[error("Process access denied (PID: {pid})")]
AccessDenied { pid: u32 },
#[error("Process not found (PID: {pid})")]
ProcessNotFound { pid: u32 },
#[error("Memory enumeration failed: {reason}")]
MemoryEnumeration { reason: String },
#[error("Thread enumeration failed: {reason}")]
ThreadEnumeration { reason: String },
#[error("Insufficient privileges for operation")]
InsufficientPrivileges,
#[error("Windows API error: {message}")]
WindowsApi { message: String },
#[error("Detection engine error: {message}")]
Detection { message: String },
}
pub type Result<T> = std::result::Result<T, GhostError>;

View File

@@ -1,9 +1,11 @@
pub mod detection;
pub mod error;
pub mod memory;
pub mod process;
pub mod thread;
pub use detection::{DetectionEngine, DetectionResult, ThreatLevel};
pub use error::{GhostError, Result};
pub use memory::{MemoryProtection, MemoryRegion};
pub use process::ProcessInfo;
pub use thread::ThreadInfo;