1use crate::collection::Error as CollectionError;
20use crate::proto::common::{ErrorCode, Status};
21use crate::schema::Error as SchemaError;
22use std::result;
23use thiserror::Error;
24use tonic::transport::Error as CommError;
25use tonic::Status as GrpcError;
26
27#[derive(Debug, Error)]
28pub enum Error {
29 #[error("{0:?}")]
30 Communication(#[from] CommError),
31
32 #[error("{0:?}")]
33 Collection(#[from] CollectionError),
34
35 #[error("{0:?}")]
36 Grpc(#[from] GrpcError),
37
38 #[error("{0:?}")]
39 Schema(#[from] SchemaError),
40
41 #[error("{0:?} {1:?}")]
42 Server(ErrorCode, String),
43
44 #[error("{0:?}")]
45 ProstEncode(#[from] prost::EncodeError),
46
47 #[error("{0:?}")]
48 ProstDecode(#[from] prost::DecodeError),
49
50 #[error("Conversion error")]
51 Conversion,
52 #[error("{0:?}")]
53 SerdeJsonErr(#[from] serde_json::Error),
54
55 #[error("parameter {0:?} with invalid value {1:?}")]
56 InvalidParameter(String, String),
57
58 #[error("{0:?}")]
59 Other(#[from] anyhow::Error),
60
61 #[error("{0}")]
62 Unexpected(String),
63}
64
65impl From<Status> for Error {
66 fn from(s: Status) -> Self {
67 Error::Server(ErrorCode::from_i32(s.error_code).unwrap(), s.reason)
68 }
69}
70
71pub type Result<T> = result::Result<T, Error>;