1use thiserror::Error;
2use tonic::codegen::http::uri;
3
4pub type Result<T> = std::result::Result<T, DanubeError>;
5
6#[derive(Debug, Error)]
7pub enum DanubeError {
8 #[error("transport error: {0}")]
9 TonicTransportError(#[from] tonic::transport::Error),
10
11 #[error("gRPC error: {0}")]
12 FromStatus(tonic::Status),
13
14 #[error("unable to parse the address: {0}")]
15 UrlParseError(#[from] uri::InvalidUri),
16
17 #[error("unable to parse the address")]
18 ParseError,
19
20 #[error("unable to load the certificate: {0}")]
21 IoError(#[from] std::io::Error),
22
23 #[error("unable to perform operation: {0}")]
24 Unrecoverable(String),
25
26 #[error("schema error: {0}")]
27 SchemaError(String),
28
29 #[error("invalid token")]
30 InvalidToken,
31}
32
33impl DanubeError {
34 pub fn extract_status(&self) -> Option<&tonic::Status> {
35 match self {
36 DanubeError::FromStatus(status) => Some(status),
37 _ => None,
38 }
39 }
40}