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

Do not unwrap when creating a bucket #82

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Changes from all 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
18 changes: 13 additions & 5 deletions src/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@
pub enum BucketError {
UnsupportedScheme,
MissingHost,
ParseError(ParseError),
}

impl From<ParseError> for BucketError {
fn from(error: ParseError) -> Self {
BucketError::ParseError(error)

Check warning on line 82 in src/bucket.rs

View check run for this annotation

Codecov / codecov/patch

src/bucket.rs#L81-L82

Added lines #L81 - L82 were not covered by tests
}
}

impl Bucket {
Expand All @@ -94,7 +101,7 @@
let name = name.into();
let region = region.into();

let base_url = base_url(endpoint, &name, path_style);
let base_url = base_url(endpoint, &name, path_style)?;

Ok(Self {
base_url,
Expand Down Expand Up @@ -128,16 +135,16 @@
}
}

fn base_url(mut endpoint: Url, name: &str, path_style: UrlStyle) -> Url {
fn base_url(mut endpoint: Url, name: &str, path_style: UrlStyle) -> Result<Url, ParseError> {
match path_style {
UrlStyle::Path => {
let path = format!("{name}/");
endpoint.join(&path).unwrap()
endpoint.join(&path)
}
UrlStyle::VirtualHost => {
let host = format!("{}.{}", name, endpoint.host_str().unwrap());
endpoint.set_host(Some(&host)).unwrap();
endpoint
endpoint.set_host(Some(&host))?;
Ok(endpoint)
}
}
}
Expand Down Expand Up @@ -311,6 +318,7 @@
match self {
Self::UnsupportedScheme => f.write_str("unsupported Url scheme"),
Self::MissingHost => f.write_str("Url is missing the `host`"),
Self::ParseError(e) => e.fmt(f),

Check warning on line 321 in src/bucket.rs

View check run for this annotation

Codecov / codecov/patch

src/bucket.rs#L321

Added line #L321 was not covered by tests
}
}
}
Expand Down
Loading