Skip to content

Commit dfd4868

Browse files
committed
Auto merge of #1271 - alexcrichton:issue-1267, r=brson
Why not use `try!` instead! Closes #1267
2 parents fc77765 + 9a9ea5a commit dfd4868

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/cargo/ops/lockfile.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ use rustc_serialize::{Encodable, Decodable};
44
use toml::{self, Encoder, Value};
55

66
use core::{Resolve, resolver, Package, SourceId};
7-
use util::CargoResult;
7+
use util::{CargoResult, ChainError, human};
88
use util::toml as cargo_toml;
99

1010
pub fn load_pkg_lockfile(pkg: &Package) -> CargoResult<Option<Resolve>> {
1111
let lockfile = pkg.get_manifest_path().dir_path().join("Cargo.lock");
1212
let source_id = pkg.get_package_id().get_source_id();
13-
load_lockfile(&lockfile, source_id)
13+
load_lockfile(&lockfile, source_id).chain_error(|| {
14+
human(format!("failed to parse lock file at: {}", lockfile.display()))
15+
})
1416
}
1517

1618
pub fn load_lockfile(path: &Path, sid: &SourceId) -> CargoResult<Option<Resolve>> {
@@ -24,7 +26,7 @@ pub fn load_lockfile(path: &Path, sid: &SourceId) -> CargoResult<Option<Resolve>
2426

2527
let table = toml::Value::Table(try!(cargo_toml::parse(s.as_slice(), path)));
2628
let mut d = toml::Decoder::new(table);
27-
let v: resolver::EncodableResolve = Decodable::decode(&mut d).unwrap();
29+
let v: resolver::EncodableResolve = try!(Decodable::decode(&mut d));
2830
Ok(Some(try!(v.to_resolve(sid))))
2931
}
3032

tests/test_bad_config.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,23 @@ Caused by:
200200
201201
"));
202202
});
203+
204+
test!(bad_cargo_lock {
205+
let foo = project("foo")
206+
.file("Cargo.toml", r#"
207+
[package]
208+
name = "foo"
209+
version = "0.0.0"
210+
authors = []
211+
"#)
212+
.file("Cargo.lock", "")
213+
.file("src/lib.rs", "");
214+
215+
assert_that(foo.cargo_process("build").arg("-v"),
216+
execs().with_status(101).with_stderr("\
217+
failed to parse lock file at: [..]Cargo.lock
218+
219+
Caused by:
220+
expected a section for the key `root`
221+
"));
222+
});

0 commit comments

Comments
 (0)