1use std::fmt;
2
3#[derive(Debug)]
5pub enum HookError {
6 CompileError(String),
8 InstantiationError(String),
10 FuelExhausted,
12 Trap(String),
14 InvalidResult(String),
16 AutoDisabled {
18 name: String,
19 consecutive_traps: u32,
20 },
21 InvalidHookPoint(String),
23 IoError(std::io::Error),
25 AbiVersionMismatch {
27 hook_name: String,
28 expected: i32,
29 found: Option<i32>,
30 },
31}
32
33impl fmt::Display for HookError {
34 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35 match self {
36 HookError::CompileError(msg) => write!(f, "compile error: {}", msg),
37 HookError::InstantiationError(msg) => write!(f, "instantiation error: {}", msg),
38 HookError::FuelExhausted => write!(f, "fuel exhausted"),
39 HookError::Trap(msg) => write!(f, "trap: {}", msg),
40 HookError::InvalidResult(msg) => write!(f, "invalid result: {}", msg),
41 HookError::AutoDisabled {
42 name,
43 consecutive_traps,
44 } => {
45 write!(
46 f,
47 "hook '{}' auto-disabled after {} consecutive traps",
48 name, consecutive_traps
49 )
50 }
51 HookError::InvalidHookPoint(msg) => write!(f, "invalid hook point: {}", msg),
52 HookError::IoError(e) => write!(f, "I/O error: {}", e),
53 HookError::AbiVersionMismatch {
54 hook_name,
55 expected,
56 found,
57 } => match found {
58 Some(v) => write!(
59 f,
60 "hook '{}' ABI version mismatch: host expects {}, hook has {}. \
61 Recompile the hook against the current rns-hooks-sdk.",
62 hook_name, expected, v
63 ),
64 None => write!(
65 f,
66 "hook '{}' missing __rns_abi_version export (expected ABI version {}). \
67 Recompile the hook against the current rns-hooks-sdk.",
68 hook_name, expected
69 ),
70 },
71 }
72 }
73}
74
75impl std::error::Error for HookError {}
76
77impl From<std::io::Error> for HookError {
78 fn from(e: std::io::Error) -> Self {
79 HookError::IoError(e)
80 }
81}