reifydb_flow_operator_sdk/
error.rs

1//! Error types for the operator SDK
2
3use std::fmt;
4
5/// FFI operator error type
6#[derive(Debug)]
7pub enum FFIError {
8	/// Configuration error
9	Configuration(String),
10
11	/// State operation error
12	StateError(String),
13
14	/// Serialization error
15	Serialization(String),
16
17	/// Invalid input parameters
18	InvalidInput(String),
19
20	/// Memory allocation error
21	MemoryError(String),
22
23	/// Operation timeout
24	Timeout,
25
26	/// Operation not implemented or not supported
27	NotImplemented(String),
28
29	/// Generic error
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::StateError(msg) => write!(f, "State error: {}", msg),
38			FFIError::Serialization(msg) => write!(f, "Serialization error: {}", msg),
39			FFIError::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
40			FFIError::MemoryError(msg) => write!(f, "Memory error: {}", msg),
41			FFIError::Timeout => write!(f, "Operation timeout"),
42			FFIError::NotImplemented(msg) => write!(f, "Not implemented: {}", msg),
43			FFIError::Other(msg) => write!(f, "{}", msg),
44		}
45	}
46}
47
48impl std::error::Error for FFIError {}
49
50/// Convert FFIError to reifydb_core::Error
51impl From<FFIError> for reifydb_core::Error {
52	fn from(err: FFIError) -> Self {
53		use reifydb_type::{Error, internal};
54		Error(internal!(format!("{}", err)))
55	}
56}
57
58/// Convert reifydb_core::Error to FFIError
59impl From<reifydb_core::Error> for FFIError {
60	fn from(err: reifydb_core::Error) -> Self {
61		FFIError::Other(err.to_string())
62	}
63}
64
65/// Result type alias for FFI operations
66pub type Result<T, E = FFIError> = std::result::Result<T, E>;