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 { name: String, consecutive_traps: u32 },
18 InvalidHookPoint(String),
20 IoError(std::io::Error),
22 AbiVersionMismatch {
24 hook_name: String,
25 expected: i32,
26 found: Option<i32>,
27 },
28}
29
30impl fmt::Display for HookError {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 match self {
33 HookError::CompileError(msg) => write!(f, "compile error: {}", msg),
34 HookError::InstantiationError(msg) => write!(f, "instantiation error: {}", msg),
35 HookError::FuelExhausted => write!(f, "fuel exhausted"),
36 HookError::Trap(msg) => write!(f, "trap: {}", msg),
37 HookError::InvalidResult(msg) => write!(f, "invalid result: {}", msg),
38 HookError::AutoDisabled { name, consecutive_traps } => {
39 write!(f, "hook '{}' auto-disabled after {} consecutive traps", name, consecutive_traps)
40 }
41 HookError::InvalidHookPoint(msg) => write!(f, "invalid hook point: {}", msg),
42 HookError::IoError(e) => write!(f, "I/O error: {}", e),
43 HookError::AbiVersionMismatch { hook_name, expected, found } => {
44 match found {
45 Some(v) => write!(
46 f,
47 "hook '{}' ABI version mismatch: host expects {}, hook has {}. \
48 Recompile the hook against the current rns-hooks-sdk.",
49 hook_name, expected, v
50 ),
51 None => write!(
52 f,
53 "hook '{}' missing __rns_abi_version export (expected ABI version {}). \
54 Recompile the hook against the current rns-hooks-sdk.",
55 hook_name, expected
56 ),
57 }
58 }
59 }
60 }
61}
62
63impl std::error::Error for HookError {}
64
65impl From<std::io::Error> for HookError {
66 fn from(e: std::io::Error) -> Self {
67 HookError::IoError(e)
68 }
69}