grafbase_sdk/component/
error.rs1use crate::wit;
2
3#[derive(Debug)]
5pub struct SdkError(SdkErrorInner);
6
7impl std::fmt::Display for SdkError {
8 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
9 write!(f, "{}", self.0)
10 }
11}
12
13impl std::error::Error for SdkError {
14 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
15 self.0.source()
16 }
17}
18
19#[derive(Debug, thiserror::Error)]
20pub(crate) enum SdkErrorInner {
21 #[error("{0}")]
22 Message(String),
23 #[error("Serialization failed with: {0}")]
24 EncodeError(#[from] minicbor_serde::error::EncodeError<std::convert::Infallible>),
25 #[error("Deserialization failed with: {0}")]
26 DecodeError(#[from] minicbor_serde::error::DecodeError),
27 #[error("JSON serialization error: {0}")]
28 Json(#[from] serde_json::Error),
29}
30
31impl<T> From<T> for SdkError
32where
33 SdkErrorInner: From<T>,
34{
35 fn from(err: T) -> Self {
36 Self(err.into())
37 }
38}
39
40impl From<String> for SdkErrorInner {
41 fn from(err: String) -> Self {
42 Self::Message(err)
43 }
44}
45
46impl From<SdkError> for wit::Error {
47 fn from(err: SdkError) -> Self {
48 wit::Error::new(err.to_string())
49 }
50}