Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add expect messages instead of unwraps #69

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("previously validated cell endpoint"),
basin_zone: basin_endpoint
.map(|b| b.parse().expect("previously validated basin endpoint")),
}
}
}
Expand Down Expand Up @@ -272,7 +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().unwrap(),
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),
Expand Down Expand Up @@ -663,7 +666,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("previously validated basin name and endpoint");
ClientInner::new(self.config.clone(), basin_endpoint, DEFAULT_HTTP_CONNECTOR)
}
None => Self {
Expand All @@ -687,16 +692,16 @@ impl ClientInner {

let endpoint = format!("{scheme}://{endpoint}")
.parse::<Endpoint>()
.unwrap()
.expect("previously validated endpoint scheme and authority")
.user_agent(config.user_agent.clone())
.unwrap()
.expect("previously validated user agent")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason here is that it is literally a HeaderValue right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how would you prefer specifying this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed it to converting HeaderValue into HeaderValue, feels much more clear

.http2_adaptive_window(true)
.tls_config(
ClientTlsConfig::default()
.with_webpki_roots()
.assume_http2(true),
)
.unwrap()
.expect("valid TLS config")
.connect_timeout(config.connection_timeout)
.timeout(config.request_timeout);

Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ pub mod types;

pub use bytesize;
pub use futures;
pub use http::uri;
pub use http::{uri, HeaderValue};
pub use secrecy::SecretString;
pub use service::Streaming;