Skip to content

Commit

Permalink
API: resolve remaining unwrap()s
Browse files Browse the repository at this point in the history
  • Loading branch information
steveej committed Oct 25, 2018
1 parent 8ac4299 commit 8452a89
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
39 changes: 34 additions & 5 deletions src/v2/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,32 @@ impl Client {
/// The name and reference parameters identify the image.
/// The reference may be either a tag or digest.
pub fn get_manifest(&self, name: &str, reference: &str) -> FutureManifest {
let url = hyper::Uri::from_str(&format!(
let url = match hyper::Uri::from_str(&format!(
"{}/v2/{}/manifests/{}",
self.base_url.clone(),
name,
reference
)).unwrap();
)) {
Ok(url) => url,
Err(e) => {
let msg = format!("failed to parse Uri from str: {}", e);
error!("msg");
return Box::new(futures::future::err::<_, _>(Error::from(msg)));
}
};
let req = {
let mut r = self.new_request(hyper::Method::GET, url.clone());
let mtype = mediatypes::MediaTypes::ManifestV2S2.to_string();
r.headers_mut().append(
header::ACCEPT,
header::HeaderValue::from_str(&mtype).unwrap(),
match header::HeaderValue::from_str(&mtype) {
Ok(headervalue) => headervalue,
Err(e) => {
let msg = format!("failed to parse HeaderValue from str: {}:", e);
error!("msg");
return Box::new(futures::future::err::<_, _>(Error::from(msg)));
}
},
);
r
};
Expand Down Expand Up @@ -71,11 +85,26 @@ impl Client {
name,
reference
);
hyper::Uri::from_str(ep.as_str()).unwrap()
match hyper::Uri::from_str(ep.as_str()) {
Ok(url) => url,
Err(e) => {
let msg = format!("failed to parse Uri from str: {}", e);
error!("msg");
return Box::new(futures::future::err::<_, _>(Error::from(msg)));
}
}
};
let accept_types = match mediatypes {
None => vec![mediatypes::MediaTypes::ManifestV2S2.to_mime()],
Some(ref v) => to_mimes(v).unwrap(),
Some(ref v) => match to_mimes(v) {
Ok(accept_types) => accept_types,
Err(e) => {
return Box::new(futures::future::err::<_, _>(Error::from(format!(
"to_mimes({:?}) failed: {}",
v, e
))));
}
},
};
let req = {
let mut r = self.new_request(hyper::Method::HEAD, url.clone());
Expand Down
12 changes: 10 additions & 2 deletions src/v2/tags.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use futures::{self, Stream};
use futures::prelude::*;
use hyper::{self, header};
use v2::*;

Expand All @@ -19,7 +19,15 @@ impl Client {
if let Some(n) = paginate {
s = s + &format!("?n={}", n);
};
hyper::Uri::from_str(s.as_str()).unwrap()
match hyper::Uri::from_str(s.as_str()) {
Ok(url) => url,
Err(e) => {
return Box::new(futures::stream::once(Err(format!(
"failed to parse url from string: {}",
e
).into())));
}
}
};
let req = self.new_request(hyper::Method::GET, url);
let freq = self.hclient.request(req);
Expand Down

0 comments on commit 8452a89

Please sign in to comment.