From 5b8a9cda6f6a8e27f960660fa62ff11e1c01dba6 Mon Sep 17 00:00:00 2001 From: Vaibhav Rabber Date: Wed, 20 Nov 2024 00:30:54 +0530 Subject: [PATCH 1/5] chore: Add expect messages instead of unwraps Signed-off-by: Vaibhav Rabber --- src/client.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/client.rs b/src/client.rs index ecc47a0..c48ee66 100644 --- a/src/client.rs +++ b/src/client.rs @@ -235,8 +235,11 @@ impl HostEndpoints { }; Self { - cell: cell_endpoint.parse().unwrap(), - basin_zone: basin_endpoint.map(|b| b.parse().unwrap()), + cell: cell_endpoint + .parse() + .expect("should be a valid cell endpoint"), + basin_zone: basin_endpoint + .map(|b| b.parse().expect("should be a valid basin endpoint")), } } } @@ -272,7 +275,9 @@ impl ClientConfig { host_endpoints: HostEndpoints::default(), connection_timeout: Duration::from_secs(3), request_timeout: Duration::from_secs(5), - user_agent: "s2-sdk-rust".parse().unwrap(), + user_agent: "s2-sdk-rust" + .parse() + .expect("should be a valid user agent ascii string"), #[cfg(feature = "connector")] uri_scheme: http::uri::Scheme::HTTPS, retry_backoff_duration: Duration::from_millis(100), @@ -663,7 +668,9 @@ impl ClientInner { fn new_basin(&self, basin: types::BasinName) -> Self { match self.config.host_endpoints.basin_zone.clone() { Some(endpoint) => { - let basin_endpoint: Authority = format!("{basin}.{endpoint}").parse().unwrap(); + let basin_endpoint: Authority = format!("{basin}.{endpoint}") + .parse() + .expect("should be a valid basin endpoint since basin name is valid"); ClientInner::new(self.config.clone(), basin_endpoint, DEFAULT_HTTP_CONNECTOR) } None => Self { @@ -687,16 +694,16 @@ impl ClientInner { let endpoint = format!("{scheme}://{endpoint}") .parse::() - .unwrap() + .expect("valid scheme and authority should result in a valid endpoint uri") .user_agent(config.user_agent.clone()) - .unwrap() + .expect("should be safe to convert HeaderValue into HeaderValue") .http2_adaptive_window(true) .tls_config( ClientTlsConfig::default() .with_webpki_roots() .assume_http2(true), ) - .unwrap() + .expect("TLS config should be valid") .connect_timeout(config.connection_timeout) .timeout(config.request_timeout); From 1a4bf1bac2f98d65a8d5beb3deb795d4d90538bf Mon Sep 17 00:00:00 2001 From: Vaibhav Rabber Date: Wed, 20 Nov 2024 00:44:03 +0530 Subject: [PATCH 2/5] .. --- src/client.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/client.rs b/src/client.rs index c48ee66..02fb781 100644 --- a/src/client.rs +++ b/src/client.rs @@ -237,9 +237,9 @@ impl HostEndpoints { Self { cell: cell_endpoint .parse() - .expect("should be a valid cell endpoint"), + .expect("previously validated cell endpoint"), basin_zone: basin_endpoint - .map(|b| b.parse().expect("should be a valid basin endpoint")), + .map(|b| b.parse().expect("previously validated basin endpoint")), } } } @@ -275,9 +275,7 @@ impl ClientConfig { host_endpoints: HostEndpoints::default(), connection_timeout: Duration::from_secs(3), request_timeout: Duration::from_secs(5), - user_agent: "s2-sdk-rust" - .parse() - .expect("should be a valid user agent ascii string"), + user_agent: "s2-sdk-rust".parse().expect("valid user agent"), #[cfg(feature = "connector")] uri_scheme: http::uri::Scheme::HTTPS, retry_backoff_duration: Duration::from_millis(100), @@ -670,7 +668,7 @@ impl ClientInner { Some(endpoint) => { let basin_endpoint: Authority = format!("{basin}.{endpoint}") .parse() - .expect("should be a valid basin endpoint since basin name is valid"); + .expect("previously validated basin name and endpoint"); ClientInner::new(self.config.clone(), basin_endpoint, DEFAULT_HTTP_CONNECTOR) } None => Self { @@ -694,16 +692,16 @@ impl ClientInner { let endpoint = format!("{scheme}://{endpoint}") .parse::() - .expect("valid scheme and authority should result in a valid endpoint uri") + .expect("previously validated endpoint scheme and authority") .user_agent(config.user_agent.clone()) - .expect("should be safe to convert HeaderValue into HeaderValue") + .expect("previously validated user agent") .http2_adaptive_window(true) .tls_config( ClientTlsConfig::default() .with_webpki_roots() .assume_http2(true), ) - .expect("TLS config should be valid") + .expect("valid TLS config") .connect_timeout(config.connection_timeout) .timeout(config.request_timeout); From 4dd8854c6e54d15383a446392ce6dfe0b0d608da Mon Sep 17 00:00:00 2001 From: Vaibhav Rabber Date: Wed, 20 Nov 2024 00:48:24 +0530 Subject: [PATCH 3/5] export Signed-off-by: Vaibhav Rabber --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 47f521b..e51983c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,5 +7,5 @@ pub mod types; pub use bytesize; pub use futures; -pub use http::uri; +pub use http::{uri, HeaderValue}; pub use secrecy::SecretString; From 2a623e680233e9b141a637975c1dbc4f96579569 Mon Sep 17 00:00:00 2001 From: Vaibhav Rabber Date: Wed, 20 Nov 2024 00:58:51 +0530 Subject: [PATCH 4/5] more export Signed-off-by: Vaibhav Rabber --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index e51983c..c87c648 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,3 +9,4 @@ pub use bytesize; pub use futures; pub use http::{uri, HeaderValue}; pub use secrecy::SecretString; +pub use service::Streaming; From cae55503716a69087760f9b461ebb30c75714b91 Mon Sep 17 00:00:00 2001 From: Vaibhav Rabber Date: Wed, 20 Nov 2024 01:08:27 +0530 Subject: [PATCH 5/5] more specific err message --- src/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client.rs b/src/client.rs index 02fb781..28052bd 100644 --- a/src/client.rs +++ b/src/client.rs @@ -694,7 +694,7 @@ impl ClientInner { .parse::() .expect("previously validated endpoint scheme and authority") .user_agent(config.user_agent.clone()) - .expect("previously validated user agent") + .expect("converting HeaderValue into HeaderValue") .http2_adaptive_window(true) .tls_config( ClientTlsConfig::default()