From c7ae466c0514ae3e66702df05a57067c057c2bc1 Mon Sep 17 00:00:00 2001 From: Adir Shitrit Date: Sat, 8 Nov 2025 11:07:48 +0200 Subject: [PATCH] add structured error handling with thiserror --- ghost-core/src/error.rs | 27 +++++++++++++++++++++++++++ ghost-core/src/lib.rs | 2 ++ 2 files changed, 29 insertions(+) create mode 100644 ghost-core/src/error.rs diff --git a/ghost-core/src/error.rs b/ghost-core/src/error.rs new file mode 100644 index 0000000..a1dba72 --- /dev/null +++ b/ghost-core/src/error.rs @@ -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 = std::result::Result; \ No newline at end of file diff --git a/ghost-core/src/lib.rs b/ghost-core/src/lib.rs index dea59bc..8708c60 100644 --- a/ghost-core/src/lib.rs +++ b/ghost-core/src/lib.rs @@ -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;