1use thiserror::Error;
6
7#[derive(Debug, Error)]
9pub enum Error {
10 #[error("failed to scan processes: {reason}")]
12 ScanFailed { reason: String },
13
14 #[error("process {pid} not accessible: {reason}")]
16 ProcessAccess { pid: u32, reason: String },
17
18 #[error("system info unavailable: {0}")]
20 SystemInfo(String),
21
22 #[error("io error: {0}")]
24 Io(#[from] std::io::Error),
25}
26
27pub 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}