From a1c13d4342789a81efab6d2c6616facffbf4624e Mon Sep 17 00:00:00 2001 From: Mohammad Kanaan Date: Mon, 27 Jul 2026 21:29:57 +0300 Subject: [PATCH] fix read_lines to better handle errors --- src/parser.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 38ae372..903a00b 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -39,16 +39,8 @@ pub fn process_files( pub fn read_lines( file_path: &Path, ) -> anyhow::Result>, 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())