1use std::fmt;
4use std::time::Duration;
5
6pub type Result<T> = std::result::Result<T, ModuleError>;
7
8#[derive(Debug, PartialEq)]
9pub enum ModuleError {
10 QuotaExceeded,
11 CallFailed(String),
12 Timeout(Duration),
13 Panic(String),
14 Serialize(String),
15 ServiceUnavailable,
16 InvalidMethod,
17 ModuleNotFound(String),
18 MaxCallDepthExceeded,
19}
20
21impl fmt::Display for ModuleError {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 match self {
24 ModuleError::QuotaExceeded => write!(f, "quota exceeded"),
25 ModuleError::CallFailed(msg) => write!(f, "call failed: {}", msg),
26 ModuleError::Timeout(duration) => write!(f, "operation timed out after {:?}", duration),
27 ModuleError::Panic(payload) => write!(f, "panic: {}", payload),
28 ModuleError::Serialize(msg) => write!(f, "serialization error: {}", msg),
29 ModuleError::ServiceUnavailable => write!(f, "service unavailable"),
30 ModuleError::InvalidMethod => write!(f, "invalid method"),
31 ModuleError::ModuleNotFound(name) => write!(f, "module not found: {}", name),
32 ModuleError::MaxCallDepthExceeded => write!(f, "maximum call depth exceeded"),
33 }
34 }
35}
36
37impl std::error::Error for ModuleError {}
38
39impl From<rmp_serde::encode::Error> for ModuleError {
40 fn from(err: rmp_serde::encode::Error) -> Self {
41 ModuleError::Serialize(err.to_string())
42 }
43}
44
45impl From<rmp_serde::decode::Error> for ModuleError {
46 fn from(err: rmp_serde::decode::Error) -> Self {
47 ModuleError::Serialize(err.to_string())
48 }
49}
50
51unsafe impl Send for ModuleError {}
52unsafe impl Sync for ModuleError {}