broccoli_server_sdk/
error.rs1use std::fmt;
2
3#[derive(Debug)]
4pub enum SdkError {
5 Serialization(String),
7 HostCall(String),
9 Database(String),
11 Other(String),
13}
14
15impl fmt::Display for SdkError {
16 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17 match self {
18 Self::Serialization(msg) => write!(f, "Serialization error: {msg}"),
19 Self::HostCall(msg) => write!(f, "Host call error: {msg}"),
20 Self::Database(msg) => write!(f, "Database error: {msg}"),
21 Self::Other(msg) => write!(f, "{msg}"),
22 }
23 }
24}
25
26impl std::error::Error for SdkError {}
27
28impl From<serde_json::Error> for SdkError {
29 fn from(e: serde_json::Error) -> Self {
30 Self::Serialization(e.to_string())
31 }
32}
33
34#[cfg(feature = "guest")]
35impl From<extism_pdk::Error> for SdkError {
36 fn from(e: extism_pdk::Error) -> Self {
37 Self::HostCall(e.to_string())
38 }
39}