Skip to main content

agentwatch_core/
error.rs

1//! Error types for AgentWatch Core
2//!
3//! Provides structured errors for agent detection and system operations.
4
5use thiserror::Error;
6
7/// Main error type for AgentWatch operations
8#[derive(Debug, Error)]
9pub enum Error {
10    /// Failed to scan system processes
11    #[error("failed to scan processes: {reason}")]
12    ScanFailed { reason: String },
13
14    /// A specific process could not be accessed
15    #[error("process {pid} not accessible: {reason}")]
16    ProcessAccess { pid: u32, reason: String },
17
18    /// System information unavailable
19    #[error("system info unavailable: {0}")]
20    SystemInfo(String),
21
22    /// IO operation failed
23    #[error("io error: {0}")]
24    Io(#[from] std::io::Error),
25}
26
27/// Result type alias for AgentWatch operations
28pub type Result<T> = std::result::Result<T, Error>;
29
30#[cfg(test)]
31mod tests {
32    use super::*;
33
34    #[test]
35    fn test_error_display() {
36        let err = Error::ScanFailed {
37            reason: "permission denied".to_string(),
38        };
39        assert_eq!(err.to_string(), "failed to scan processes: permission denied");
40    }
41
42    #[test]
43    fn test_process_access_error() {
44        let err = Error::ProcessAccess {
45            pid: 1234,
46            reason: "zombie process".to_string(),
47        };
48        assert!(err.to_string().contains("1234"));
49        assert!(err.to_string().contains("zombie"));
50    }
51}