From ee6e726707a6839c6cabe672eb296c6118a2a1cd Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Tue, 22 Feb 2022 14:58:22 -0500 Subject: [PATCH] fix(transport): Endpoint returns transport error (#920) --- tonic/src/transport/channel/endpoint.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tonic/src/transport/channel/endpoint.rs b/tonic/src/transport/channel/endpoint.rs index 3a0b5b896..af2d16f36 100644 --- a/tonic/src/transport/channel/endpoint.rs +++ b/tonic/src/transport/channel/endpoint.rs @@ -6,10 +6,7 @@ use super::ClientTlsConfig; use crate::transport::service::TlsConnector; use crate::transport::Error; use bytes::Bytes; -use http::{ - uri::{InvalidUri, Uri}, - HeaderValue, -}; +use http::{uri::Uri, HeaderValue}; use std::{ convert::{TryFrom, TryInto}, fmt, @@ -76,8 +73,8 @@ impl Endpoint { /// # use tonic::transport::Endpoint; /// Endpoint::from_shared("https://example.com".to_string()); /// ``` - pub fn from_shared(s: impl Into) -> Result { - let uri = Uri::from_maybe_shared(s.into())?; + pub fn from_shared(s: impl Into) -> Result { + let uri = Uri::from_maybe_shared(s.into()).map_err(|e| Error::new_invalid_uri().with(e))?; Ok(Self::from(uri)) } @@ -404,7 +401,7 @@ impl From for Endpoint { } impl TryFrom for Endpoint { - type Error = InvalidUri; + type Error = Error; fn try_from(t: Bytes) -> Result { Self::from_shared(t) @@ -412,7 +409,7 @@ impl TryFrom for Endpoint { } impl TryFrom for Endpoint { - type Error = InvalidUri; + type Error = Error; fn try_from(t: String) -> Result { Self::from_shared(t.into_bytes()) @@ -420,7 +417,7 @@ impl TryFrom for Endpoint { } impl TryFrom<&'static str> for Endpoint { - type Error = InvalidUri; + type Error = Error; fn try_from(t: &'static str) -> Result { Self::from_shared(t.as_bytes()) @@ -434,7 +431,7 @@ impl fmt::Debug for Endpoint { } impl FromStr for Endpoint { - type Err = InvalidUri; + type Err = Error; fn from_str(s: &str) -> Result { Self::try_from(s.to_string())