propagate errors
This commit is contained in:
+9
-7
@@ -3,6 +3,8 @@ use std::fs::File;
|
|||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::io::{BufRead, BufReader};
|
use std::io::{BufRead, BufReader};
|
||||||
|
|
||||||
|
use anyhow::{anyhow, Context, Result};
|
||||||
|
|
||||||
use crate::Package;
|
use crate::Package;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -12,22 +14,22 @@ pub struct Group {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Group {
|
impl Group {
|
||||||
pub fn load_from_dir() -> HashSet<Self> {
|
pub fn load_from_dir() -> Result<HashSet<Self>> {
|
||||||
let mut result = HashSet::new();
|
let mut result = HashSet::new();
|
||||||
let path = crate::path::get_pacdef_group_dir().unwrap();
|
let path = crate::path::get_pacdef_group_dir().context("getting pacdef group dir")?;
|
||||||
for entry in path.read_dir().unwrap() {
|
for entry in path.read_dir().context("reading group dir")? {
|
||||||
let file = entry.unwrap();
|
let file = entry.context("getting a file")?;
|
||||||
let name = file.file_name();
|
let name = file.file_name();
|
||||||
let f = File::open(file.path()).unwrap();
|
let f = File::open(file.path()).context("reading the file")?;
|
||||||
let reader = BufReader::new(f);
|
let reader = BufReader::new(f);
|
||||||
|
|
||||||
let packages = Package::from_lines(reader.lines());
|
let packages = Package::from_lines(reader.lines());
|
||||||
result.insert(Group {
|
result.insert(Group {
|
||||||
name: name.into_string().unwrap(),
|
name: name.into_string().map_err(|e| anyhow!(e))?,
|
||||||
packages,
|
packages,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
result
|
Ok(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -6,6 +6,5 @@ fn main() -> Result<()> {
|
|||||||
let args = args::get_args();
|
let args = args::get_args();
|
||||||
let groups = Group::load_from_dir();
|
let groups = Group::load_from_dir();
|
||||||
let pacdef = Pacdef::new(args, groups);
|
let pacdef = Pacdef::new(args, groups);
|
||||||
pacdef.run_action_from_arg().context("running action")?;
|
pacdef.run_action_from_arg().context("running action")
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user