chroma_types/
types.rs

1use chroma_error::{ChromaError, ErrorCodes};
2use thiserror::Error;
3use tonic::Status;
4
5/// A macro for easily implementing match arms for a base error type with common errors.
6/// Other types can wrap it and still implement the ChromaError trait
7/// without boilerplate.
8macro_rules! impl_base_convert_error {
9    ($err:ty, { $($variant:pat => $action:expr),* $(,)? }) => {
10        impl ChromaError for $err {
11            fn code(&self) -> ErrorCodes {
12                match self {
13                    Self::DecodeError(inner) => inner.code(),
14                    // Handle custom variants
15                    $( $variant => $action, )*
16                }
17            }
18        }
19    };
20}
21
22#[derive(Error, Debug)]
23pub enum ConversionError {
24    #[error("Error decoding protobuf message")]
25    DecodeError,
26}
27
28impl ChromaError for ConversionError {
29    fn code(&self) -> ErrorCodes {
30        ErrorCodes::InvalidArgument
31    }
32}
33
34impl From<ConversionError> for Status {
35    fn from(value: ConversionError) -> Self {
36        Status::invalid_argument(value.to_string())
37    }
38}
39
40#[derive(thiserror::Error, Debug)]
41#[error(transparent)]
42pub enum WrappedSerdeJsonError {
43    #[error(transparent)]
44    SerdeJsonError(#[from] serde_json::Error),
45}
46
47impl ChromaError for WrappedSerdeJsonError {
48    fn code(&self) -> ErrorCodes {
49        ErrorCodes::InvalidArgument
50    }
51}