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