diff --git a/src/v2/manifest/mod.rs b/src/v2/manifest/mod.rs index 083d9914..19f4408d 100644 --- a/src/v2/manifest/mod.rs +++ b/src/v2/manifest/mod.rs @@ -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 }; @@ -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()); diff --git a/src/v2/tags.rs b/src/v2/tags.rs index cd42d3a8..72afd298 100644 --- a/src/v2/tags.rs +++ b/src/v2/tags.rs @@ -1,4 +1,4 @@ -use futures::{self, Stream}; +use futures::prelude::*; use hyper::{self, header}; use v2::*; @@ -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);