1#![allow(clippy::module_name_repetitions, clippy::enum_variant_names)]
2use prost_reflect::DescriptorError;
3use thiserror::Error as ThisError;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(ThisError, Debug)]
10pub enum Error {
11 #[error("internal error {0}")]
13 Internal(String),
14
15 #[error("error deserializing message from json")]
17 DeserializeMessage(#[source] serde_json::Error),
18
19 #[error("error compiling proto files")]
21 ProtoxCompileError(#[source] protox::Error),
22
23 #[error("error generating the descriptor pool")]
25 DescriptorError(#[source] DescriptorError),
26
27 #[error("error creating grpc channel")]
29 GrpcChannelCreateError(#[source] protox::Error),
30
31 #[error("grpc channel is not ready: {0}")]
33 GrpcNotReady(#[from] tonic::transport::Error),
34
35 #[error("grpc: {0}")]
37 GrpcError(GrpcStatus),
38
39 #[error("failed to load custom TLS certificate")]
41 LoadTLSCertificateError(#[source] std::io::Error),
42
43 #[error("failed to serialize proto message")]
45 SerializeJsonError(#[source] serde_json::Error),
46
47 #[error("failed to serialize the message")]
49 SerializeMessageError(String),
50
51 #[error("error parsing to ascii")]
53 ParseToAsciiError,
54}
55
56impl From<tonic::Status> for Error {
57 fn from(status: tonic::Status) -> Self {
58 Self::GrpcError(status.into())
59 }
60}
61
62#[derive(Debug)]
64pub struct GrpcStatus {
65 pub code: tonic::Code,
67 pub message: String,
69}
70
71impl std::fmt::Display for GrpcStatus {
72 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
73 write!(f, "status: {:?}, message: {:?}", self.code, self.message)
74 }
75}
76
77impl From<tonic::Status> for GrpcStatus {
78 fn from(status: tonic::Status) -> Self {
79 GrpcStatus {
80 code: status.code(),
81 message: status.message().to_owned(),
82 }
83 }
84}
85
86pub const FROM_UTF8: &str = "From UTF8 error";