fix: include underlying error message in connection error (#2326)
* fix: include underlying error message in connection error * fix: clippy Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>pull/24376/head
parent
a0e06014b7
commit
e62790cf4b
|
@ -15,10 +15,6 @@ pub enum Error {
|
|||
#[error("Received invalid response: {}", .0)]
|
||||
InvalidResponse(i32),
|
||||
|
||||
/// Error connecting to the server
|
||||
#[error("Connection error: {}", .0)]
|
||||
ConnectionError(#[from] tonic::transport::Error),
|
||||
|
||||
/// Client received an unexpected error from the server
|
||||
#[error("Unexpected server error: {}: {}", .0.code(), .0.message())]
|
||||
UnexpectedError(#[from] tonic::Status),
|
||||
|
|
|
@ -20,14 +20,33 @@ pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(30);
|
|||
#[derive(Debug, Error)]
|
||||
pub enum Error {
|
||||
/// Server returned an invalid argument error
|
||||
#[error("Connection error: {}", .0)]
|
||||
TransportError(#[from] tonic::transport::Error),
|
||||
#[error("Connection error: {}{}", source, details)]
|
||||
TransportError {
|
||||
/// underlying [`tonic::transport::Error`]
|
||||
source: tonic::transport::Error,
|
||||
/// stringified version of the tonic error's source
|
||||
details: String,
|
||||
},
|
||||
|
||||
/// Client received an unexpected error from the server
|
||||
#[error("Invalid URI: {}", .0)]
|
||||
InvalidUri(#[from] InvalidUri),
|
||||
}
|
||||
|
||||
// Custom impl to include underlying source (not included in tonic
|
||||
// transport error)
|
||||
impl From<tonic::transport::Error> for Error {
|
||||
fn from(source: tonic::transport::Error) -> Self {
|
||||
use std::error::Error;
|
||||
let details = source
|
||||
.source()
|
||||
.map(|e| format!(" ({})", e))
|
||||
.unwrap_or_else(|| "".to_string());
|
||||
|
||||
Self::TransportError { source, details }
|
||||
}
|
||||
}
|
||||
|
||||
/// Result type for the ConnectionBuilder
|
||||
pub type Result<T, E = Error> = std::result::Result<T, E>;
|
||||
|
||||
|
|
|
@ -23,8 +23,11 @@ mod write_pb;
|
|||
|
||||
#[derive(Debug, Snafu)]
|
||||
pub enum Error {
|
||||
#[snafu(display("gRPC transport error: {}", source))]
|
||||
TransportError { source: tonic::transport::Error },
|
||||
#[snafu(display("gRPC transport error: {}{}", source, details))]
|
||||
TransportError {
|
||||
source: tonic::transport::Error,
|
||||
details: String,
|
||||
},
|
||||
|
||||
#[snafu(display("gRPC reflection error: {}", source))]
|
||||
ReflectionError {
|
||||
|
@ -34,6 +37,20 @@ pub enum Error {
|
|||
|
||||
pub type Result<T, E = Error> = std::result::Result<T, E>;
|
||||
|
||||
// Custom impl to include underlying source (not included in tonic
|
||||
// transport error)
|
||||
impl From<tonic::transport::Error> for Error {
|
||||
fn from(source: tonic::transport::Error) -> Self {
|
||||
use std::error::Error;
|
||||
let details = source
|
||||
.source()
|
||||
.map(|e| format!(" ({})", e))
|
||||
.unwrap_or_else(|| "".to_string());
|
||||
|
||||
Self::TransportError { source, details }
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the name of the gRPC service S.
|
||||
fn service_name<S: NamedService>(_: &S) -> &'static str {
|
||||
S::NAME
|
||||
|
@ -139,6 +156,7 @@ where
|
|||
|
||||
builder
|
||||
.serve_with_incoming_shutdown(stream, shutdown.cancelled())
|
||||
.await
|
||||
.context(TransportError)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue