diff --git a/src/exec.rs b/src/exec.rs index 2eedb7be..d1b73524 100644 --- a/src/exec.rs +++ b/src/exec.rs @@ -305,9 +305,9 @@ impl ExecResizeOptions { { for (k, v) in params.iter() { let key = k.to_string(); - let value = serde_json::to_value(v).unwrap(); - - body.insert(key, value); + if let Ok(value) = serde_json::to_value(v) { + body.insert(key, value); + } } } diff --git a/src/network.rs b/src/network.rs index 6dd4eb3d..cbe55410 100644 --- a/src/network.rs +++ b/src/network.rs @@ -202,9 +202,9 @@ impl NetworkCreateOptions { { for (k, v) in params.iter() { let key = k.to_string(); - let value = serde_json::to_value(v).unwrap(); - - body.insert(key, value); + if let Ok(value) = serde_json::to_value(v) { + body.insert(key, value); + } } } } @@ -269,9 +269,9 @@ impl ContainerConnectionOptions { { for (k, v) in params.iter() { let key = k.to_string(); - let value = serde_json::to_value(v).unwrap(); - - body.insert(key, value); + if let Ok(value) = serde_json::to_value(v) { + body.insert(key, value); + } } } diff --git a/src/service.rs b/src/service.rs index 9c255225..2bf22942 100644 --- a/src/service.rs +++ b/src/service.rs @@ -199,11 +199,16 @@ impl ServiceListOptionsBuilder { ServiceFilter::Name(n) => param.insert("name", vec![n.to_string()]), }; } - // structure is a a json encoded object mapping string keys to a list - // of string values - self.params - .insert("filters", serde_json::to_string(¶m).unwrap()); - self + + if let Ok(structure) = serde_json::to_string(¶m) { + // structure is a a json encoded object mapping string keys to a list + // of string values + self.params.insert("filters", structure); + return self; + } else { + // TODO: Handle serde_json::to_string serialization error + panic!(); + } } pub fn enable_status(&mut self) -> &mut Self { diff --git a/src/tarball.rs b/src/tarball.rs index 06a03627..0893bea1 100644 --- a/src/tarball.rs +++ b/src/tarball.rs @@ -41,8 +41,11 @@ where { let base_path = Path::new(path).canonicalize()?; - // todo: don't unwrap - let mut base_path_str = base_path.to_str().unwrap().to_owned(); + let mut base_path_str = String::new(); + if let Some(value) = base_path.to_str() { + base_path_str = value.to_owned(); + } + if let Some(last) = base_path_str.chars().last() { if last != MAIN_SEPARATOR { base_path_str.push(MAIN_SEPARATOR) @@ -51,16 +54,14 @@ where let mut append = |path: &Path| { let canonical = path.canonicalize()?; - // todo: don't unwrap - let relativized = canonical - .to_str() - .unwrap() - .trim_start_matches(&base_path_str[..]); - if path.is_dir() { - archive.append_dir(Path::new(relativized), &canonical)? - } else { - archive.append_file(Path::new(relativized), &mut File::open(&canonical)?)? + if let Some(relativized) = canonical.to_str() { + if path.is_dir() { + archive.append_dir(Path::new(relativized.trim_start_matches(&base_path_str[..])), &canonical)? + } else { + archive.append_file(Path::new(relativized.trim_start_matches(&base_path_str[..])), &mut File::open(&canonical)?)? + } } + Ok(()) }; bundle(Path::new(path), &mut append, false)?;