Skip to main content

reifydb_sdk/
error.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4//! Error types for the operator SDK
5
6use std::{error, fmt};
7
8use reifydb_core::internal;
9use reifydb_type::error::Error;
10
11/// FFI operator error type
12#[derive(Debug)]
13pub enum FFIError {
14	/// Configuration error
15	Configuration(String),
16
17	/// State operation error
18	StateError(String),
19
20	/// Serialization error
21	Serialization(String),
22
23	/// Invalid input parameters
24	InvalidInput(String),
25
26	/// Memory allocation error
27	MemoryError(String),
28
29	/// Operation timeout
30	Timeout,
31
32	/// Operation not implemented or not supported
33	NotImplemented(String),
34
35	/// Generic error
36	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
56/// Convert FFIError to Error
57impl From<FFIError> for Error {
58	fn from(err: FFIError) -> Self {
59		Error(Box::new(internal!(format!("{}", err))))
60	}
61}
62
63/// Convert Error to FFIError
64impl From<Error> for FFIError {
65	fn from(err: Error) -> Self {
66		FFIError::Other(err.to_string())
67	}
68}
69
70/// Result type alias for FFI operations
71pub type Result<T, E = FFIError> = std::result::Result<T, E>;