improve error handling

This commit is contained in:
Dr. Matthias Ratajczak
2023-01-10 18:00:02 +01:00
parent cff3784487
commit 1365ee5b5c
3 changed files with 28 additions and 8 deletions
+5 -4
View File
@@ -21,14 +21,15 @@ impl Backend for Rust {
impl_backend_constants!();
fn get_all_installed_packages(&self) -> Result<HashSet<Package>> {
let file = get_crates_file().unwrap();
let content = read_to_string(file).unwrap();
let json: Value = serde_json::from_str(&content).unwrap();
extract_packages(json)
let file = get_crates_file().context("getting path to crates file")?;
let content = read_to_string(file).context("reading crates file")?;
let json: Value = serde_json::from_str(&content).context("parsing JSON")?;
extract_packages(json).context("extracing packages from JSON")
}
fn get_explicitly_installed_packages(&self) -> Result<HashSet<Package>> {
self.get_all_installed_packages()
.context("getting all installed packages")
}
}