Skip to content

Commit d2d3292

Browse files
committed
UpstreamIndex: Return Result from crates_from_index_head()
1 parent ef6a7f8 commit d2d3292

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/tests/git.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,26 @@ impl UpstreamIndex {
2525
}
2626

2727
/// Obtain a list of crates from the index HEAD
28-
pub fn crates_from_index_head(&self, crate_name: &str) -> Vec<cargo_registry::git::Crate> {
28+
pub fn crates_from_index_head(
29+
&self,
30+
crate_name: &str,
31+
) -> anyhow::Result<Vec<cargo_registry::git::Crate>> {
2932
let repo = &self.repository;
3033

3134
let path = cargo_registry::git::Repository::relative_index_file(crate_name);
32-
let tree = repo.head().unwrap().peel_to_tree().unwrap();
33-
let blob = tree
34-
.get_path(&path)
35-
.unwrap()
36-
.to_object(repo)
37-
.unwrap()
38-
.peel_to_blob()
39-
.unwrap();
35+
36+
let head = repo.head()?;
37+
let tree = head.peel_to_tree()?;
38+
let blob = tree.get_path(&path)?.to_object(repo)?.peel_to_blob()?;
39+
4040
let content = blob.content();
4141

4242
// The index format consists of one JSON object per line
4343
// It is not a JSON array
44-
let lines = std::str::from_utf8(content).unwrap().lines();
45-
lines
46-
.map(|line| serde_json::from_str(line).unwrap())
47-
.collect()
44+
let lines = std::str::from_utf8(content)?.lines();
45+
let versions = lines.map(serde_json::from_str).collect::<Result<_, _>>()?;
46+
47+
Ok(versions)
4848
}
4949

5050
pub fn create_empty_commit(&self) -> anyhow::Result<()> {

src/tests/util/test_app.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ impl TestApp {
134134

135135
/// Obtain a list of crates from the index HEAD
136136
pub fn crates_from_index_head(&self, crate_name: &str) -> Vec<cargo_registry::git::Crate> {
137-
self.upstream_index().crates_from_index_head(crate_name)
137+
self.upstream_index()
138+
.crates_from_index_head(crate_name)
139+
.unwrap()
138140
}
139141

140142
pub fn run_pending_background_jobs(&self) {

0 commit comments

Comments
 (0)