#![allow(clippy::module_name_repetitions, clippy::enum_variant_names)]
use prost_reflect::DescriptorError;
use thiserror::Error as ThisError;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(ThisError, Debug)]
pub enum Error {
#[error("internal error {0}")]
Internal(String),
#[error("error deserializing message from json")]
DeserializeMessage(#[source] serde_json::Error),
#[error("error compiling proto files")]
ProtoxCompileError(#[source] protox::Error),
#[error("error generating the descriptor pool")]
DescriptorError(#[source] DescriptorError),
#[error("error creating grpc channel")]
GrpcChannelCreateError(#[source] protox::Error),
#[error("grpc channel is not ready: {0}")]
GrpcNotReady(#[from] tonic::transport::Error),
#[error("grpc: {0}")]
GrpcError(GrpcStatus),
#[error("failed to load custom TLS certificate")]
LoadTLSCertificateError(#[source] std::io::Error),
#[error("failed to serialize proto message")]
SerializeJsonError(#[source] serde_json::Error),
#[error("failed to serialize the message")]
SerializeMessageError(String),
#[error("error parsing to ascii")]
ParseToAsciiError,
}
impl From<tonic::Status> for Error {
fn from(status: tonic::Status) -> Self {
Self::GrpcError(status.into())
}
}
#[derive(Debug)]
pub struct GrpcStatus {
pub code: tonic::Code,
pub message: String,
}
impl std::fmt::Display for GrpcStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "status: {:?}, message: {:?}", self.code, self.message)
}
}
impl From<tonic::Status> for GrpcStatus {
fn from(status: tonic::Status) -> Self {
GrpcStatus {
code: status.code(),
message: status.message().to_owned(),
}
}
}
pub const FROM_UTF8: &str = "From UTF8 error";