fix read_lines to better handle errors
This commit is contained in:
parent
0f57d037e0
commit
a1c13d4342
1 changed files with 2 additions and 10 deletions
|
|
@ -39,16 +39,8 @@ pub fn process_files(
|
|||
pub fn read_lines(
|
||||
file_path: &Path,
|
||||
) -> anyhow::Result<impl Iterator<Item = std::io::Result<String>>, anyhow::Error> {
|
||||
match file_path.try_exists() {
|
||||
Ok(true) => {}
|
||||
Ok(false) => return Err(anyhow::anyhow!("File path needs to exist")),
|
||||
Err(e) => eprintln!("Error checking path: {e}"),
|
||||
}
|
||||
|
||||
let path_string = file_path.to_string_lossy().to_string();
|
||||
|
||||
let file =
|
||||
File::open(file_path).with_context(|| format!("failed to open file: {path_string}"))?;
|
||||
let file = File::open(file_path)
|
||||
.with_context(|| format!("failed to open file: {}", file_path.display()))?;
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
Ok(reader.lines())
|
||||
|
|
|
|||
Loading…
Reference in a new issue