Skip to content

Remove/refactor some .unwraps & make some JSON valid. #78

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
15 changes: 8 additions & 7 deletions src/bin/cargo-verify-project.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ fn main() {
}
};

if !matches.opt_present("m") {
fail("missing-argument", "manifest");
return;
}

let manifest = matches.opt_str("m").unwrap();
let manifest = match matches.opt_str("m") {
Some(m) => m,
None => {
fail("missing-argument", "manifest");
return;
}
};
let file = Path::new(manifest);
let contents = match File::open(&file).read_to_str() {
Ok(s) => s,
Expand All @@ -50,6 +51,6 @@ fn main() {
}

fn fail(reason: &str, value: &str) {
println!(r#"{{ "{:s}", "{:s}" }}"#, reason, value);
println!(r#"{{ "{:s}": "{:s}" }}"#, reason, value);
set_exit_status(1);
}
5 changes: 3 additions & 2 deletions src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,13 @@ impl PackageSet {
}

pub fn pop(&mut self) -> Package {
self.packages.pop().unwrap()
self.packages.pop().expect("PackageSet.pop: empty set")
}

/// Get a package by name out of the set
pub fn get<'a>(&'a self, name: &str) -> &'a Package {
self.packages.iter().find(|pkg| name == pkg.get_name()).unwrap()
self.packages.iter().find(|pkg| name == pkg.get_name())
.expect("PackageSet.get: empty set")
}

pub fn get_all<'a>(&'a self, names: &[&str]) -> Vec<&'a Package> {
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/ops/cargo_rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ fn compile_custom(pkg: &Package, cmd: &str, cx: &Context) -> CargoResult<()> {
let mut cmd = cmd.split(' ');
let mut p = util::process(cmd.next().unwrap())
.cwd(pkg.get_root())
.env("OUT_DIR", Some(cx.dest.as_str().unwrap()))
.env("OUT_DIR", Some(cx.dest.as_str().expect("non-UTF8 dest path")))
.env("DEPS_DIR", Some(cx.dest.join(cx.deps_dir)
.as_str().unwrap()));
.as_str().expect("non-UTF8 deps path")));
for arg in cmd {
p = p.arg(arg);
}
Expand Down
22 changes: 10 additions & 12 deletions src/cargo/util/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{io,fmt,os};
use std::{io,fmt,os, result};
use std::collections::HashMap;
use serialize::{Encodable,Encoder};
use toml;
Expand Down Expand Up @@ -231,17 +231,15 @@ fn merge_array(existing: &mut ConfigValue, val: &[toml::Value],
match existing.value {
String(_) => Err(internal("should be an Array, but it was a String")),
List(ref mut list) => {
let new_list: Vec<CargoResult<String>> =
val.iter().map(toml_string).collect();
if new_list.iter().any(|v| v.is_err()) {
return Err(internal("should be an Array of Strings, but \
was an Array of other values"));
} else {
let new_list: Vec<String> =
new_list.move_iter().map(|v| v.unwrap()).collect();
list.push_all(new_list.as_slice());
existing.path.push(path.clone());
Ok(())
let r: CargoResult<Vec<String>> = result::collect(val.iter().map(toml_string));
match r {
Err(_) => Err(internal("should be an Array of Strings, but \
was an Array of other values")),
Ok(new_list) => {
list.push_all(new_list.as_slice());
existing.path.push(path.clone());
Ok(())
}
}
}
}
Expand Down