Skip to main content

reifydb_sdk/
error.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4use std::{error, fmt};
5
6use reifydb_core::internal;
7use reifydb_type::error::Error;
8
9#[derive(Debug)]
10pub enum FFIError {
11	/// Configuration error
12	Configuration(String),
13
14	/// Required configuration key is missing
15	MissingConfiguration {
16		operator: &'static str,
17		key: &'static str,
18	},
19
20	/// State operation error
21	StateError(String),
22
23	/// Serialization error
24	Serialization(String),
25
26	/// Invalid input parameters
27	InvalidInput(String),
28
29	/// Memory allocation error
30	MemoryError(String),
31
32	/// Operation timeout
33	Timeout,
34
35	/// Operation not implemented or not supported
36	NotImplemented(String),
37
38	/// Generic error
39	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>;