1use std::{error, fmt};
5
6use reifydb_core::internal;
7use reifydb_type::error::Error;
8
9#[derive(Debug)]
10pub enum FFIError {
11 Configuration(String),
13
14 MissingConfiguration {
16 operator: &'static str,
17 key: &'static str,
18 },
19
20 StateError(String),
22
23 Serialization(String),
25
26 InvalidInput(String),
28
29 MemoryError(String),
31
32 Timeout,
34
35 NotImplemented(String),
37
38 Other(String),
40}
41
42impl fmt::Display for FFIError {
43 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44 match self {
45 FFIError::Configuration(msg) => write!(f, "Configuration error: {}", msg),
46 FFIError::MissingConfiguration {
47 operator,
48 key,
49 } => {
50 write!(f, "{operator} requires '{key}' configuration")
51 }
52 FFIError::StateError(msg) => write!(f, "State error: {}", msg),
53 FFIError::Serialization(msg) => write!(f, "Serialization error: {}", msg),
54 FFIError::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
55 FFIError::MemoryError(msg) => write!(f, "Memory error: {}", msg),
56 FFIError::Timeout => write!(f, "Operation timeout"),
57 FFIError::NotImplemented(msg) => write!(f, "Not implemented: {}", msg),
58 FFIError::Other(msg) => write!(f, "{}", msg),
59 }
60 }
61}
62
63impl error::Error for FFIError {}
64
65impl From<FFIError> for Error {
66 fn from(err: FFIError) -> Self {
67 Error(Box::new(internal!(format!("{}", err))))
68 }
69}
70
71impl From<Error> for FFIError {
72 fn from(err: Error) -> Self {
73 FFIError::Other(err.to_string())
74 }
75}
76
77pub type Result<T, E = FFIError> = std::result::Result<T, E>;