1use std::{error, fmt};
5
6use reifydb_core::internal;
7use reifydb_type::error::Error;
8
9#[derive(Debug)]
10pub enum FFIError {
11 Configuration(String),
12
13 MissingConfiguration {
14 operator: &'static str,
15 key: &'static str,
16 },
17
18 StateError(String),
19
20 Serialization(String),
21
22 InvalidInput(String),
23
24 MemoryError(String),
25
26 Timeout,
27
28 NotImplemented(String),
29
30 Other(String),
31}
32
33impl fmt::Display for FFIError {
34 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35 match self {
36 FFIError::Configuration(msg) => write!(f, "Configuration error: {}", msg),
37 FFIError::MissingConfiguration {
38 operator,
39 key,
40 } => {
41 write!(f, "{operator} requires '{key}' configuration")
42 }
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 {
57 fn from(err: FFIError) -> Self {
58 Error(Box::new(internal!(format!("{}", err))))
59 }
60}
61
62impl From<Error> for FFIError {
63 fn from(err: Error) -> Self {
64 FFIError::Other(err.to_string())
65 }
66}
67
68pub type Result<T, E = FFIError> = std::result::Result<T, E>;