diff --git a/influxdb_iox_client/src/client/health.rs b/influxdb_iox_client/src/client/health.rs index 9199f991f2..94f9e46c12 100644 --- a/influxdb_iox_client/src/client/health.rs +++ b/influxdb_iox_client/src/client/health.rs @@ -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), diff --git a/influxdb_iox_client/src/connection.rs b/influxdb_iox_client/src/connection.rs index 43bee07444..8caf2c234b 100644 --- a/influxdb_iox_client/src/connection.rs +++ b/influxdb_iox_client/src/connection.rs @@ -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 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 = std::result::Result; diff --git a/src/influxdb_ioxd/rpc.rs b/src/influxdb_ioxd/rpc.rs index 2e2145c4aa..fa388d3e9e 100644 --- a/src/influxdb_ioxd/rpc.rs +++ b/src/influxdb_ioxd/rpc.rs @@ -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 = std::result::Result; +// Custom impl to include underlying source (not included in tonic +// transport error) +impl From 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) -> &'static str { S::NAME @@ -139,6 +156,7 @@ where builder .serve_with_incoming_shutdown(stream, shutdown.cancelled()) - .await - .context(TransportError) + .await?; + + Ok(()) }