1use thiserror::Error;
4
5#[derive(Debug, Clone, PartialEq, Eq, Error)]
7pub enum HookError {
8 #[error("invalid FQL pattern: {0}")]
10 InvalidFql(String),
11
12 #[error("unknown hook point: {0}")]
14 UnknownHookPoint(String),
15
16 #[error("hook execution failed [{hook_id}]: {message}")]
18 ExecutionFailed {
19 hook_id: String,
21 message: String,
23 },
24
25 #[error("hook not found: {0}")]
27 NotFound(String),
28
29 #[error("depth limit exceeded (depth={depth}, max={max_depth})")]
31 DepthExceeded {
32 depth: u8,
34 max_depth: u8,
36 },
37}
38
39#[cfg(test)]
40mod tests {
41 use super::*;
42
43 #[test]
44 fn display_invalid_fql() {
45 let err = HookError::InvalidFql("missing ::".into());
46 assert_eq!(err.to_string(), "invalid FQL pattern: missing ::");
47 }
48
49 #[test]
50 fn display_unknown_hook_point() {
51 let err = HookError::UnknownHookPoint("foo.bar".into());
52 assert_eq!(err.to_string(), "unknown hook point: foo.bar");
53 }
54
55 #[test]
56 fn display_execution_failed() {
57 let err = HookError::ExecutionFailed {
58 hook_id: "audit-hook".into(),
59 message: "lua error".into(),
60 };
61 assert_eq!(
62 err.to_string(),
63 "hook execution failed [audit-hook]: lua error"
64 );
65 }
66
67 #[test]
68 fn display_not_found() {
69 let err = HookError::NotFound("my-hook".into());
70 assert_eq!(err.to_string(), "hook not found: my-hook");
71 }
72
73 #[test]
74 fn display_depth_exceeded() {
75 let err = HookError::DepthExceeded {
76 depth: 5,
77 max_depth: 4,
78 };
79 assert_eq!(err.to_string(), "depth limit exceeded (depth=5, max=4)");
80 }
81
82 #[test]
83 fn error_is_clone_and_eq() {
84 let a = HookError::NotFound("x".into());
85 let b = a.clone();
86 assert_eq!(a, b);
87 }
88}