1use std::{error, fmt};
5
6use reifydb_core::internal;
7use reifydb_value::error::Error;
8
9#[derive(Debug)]
10pub enum SdkError {
11 Configuration(String),
12
13 MissingConfiguration {
14 operator: &'static str,
15 key: &'static str,
16 },
17
18 OperatorError(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 SdkError {
34 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35 match self {
36 SdkError::Configuration(msg) => write!(f, "Configuration error: {}", msg),
37 SdkError::MissingConfiguration {
38 operator,
39 key,
40 } => {
41 write!(f, "{operator} requires '{key}' configuration")
42 }
43 SdkError::OperatorError(msg) => write!(f, "State error: {}", msg),
44 SdkError::Serialization(msg) => write!(f, "Serialization error: {}", msg),
45 SdkError::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
46 SdkError::MemoryError(msg) => write!(f, "Memory error: {}", msg),
47 SdkError::Timeout => write!(f, "Operation timeout"),
48 SdkError::NotImplemented(msg) => write!(f, "Not implemented: {}", msg),
49 SdkError::Other(msg) => write!(f, "{}", msg),
50 }
51 }
52}
53
54impl error::Error for SdkError {}
55
56impl From<SdkError> for Error {
57 fn from(err: SdkError) -> Self {
58 Error(Box::new(internal!(format!("{}", err))))
59 }
60}
61
62impl From<Error> for SdkError {
63 fn from(err: Error) -> Self {
64 SdkError::Other(err.to_string())
65 }
66}
67
68pub type Result<T, E = SdkError> = std::result::Result<T, E>;