From 0ed74c6a51618363629638d38fab49d10ee78b32 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Mon, 2 Jun 2025 09:48:23 +0300 Subject: [PATCH] nff: handle errors and exit appropriately in linter --- src/main.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index fd2bca4..88f6116 100755 --- a/src/main.rs +++ b/src/main.rs @@ -351,6 +351,8 @@ fn process_lint_command( }; let is_multiple_files = files.len() > 1; + let mut has_errors = false; + for file_path in files { if let Err(e) = process_single_file_lint( &file_path, @@ -364,12 +366,18 @@ fn process_lint_command( is_multiple_files, ) { eprintln!("Error processing {}: {}", file_path, e); + has_errors = true; if !is_multiple_files { return Err(e); } } } + // Exit with non-zero code if any file had errors + if has_errors { + std::process::exit(1); + } + Ok(()) } @@ -459,9 +467,9 @@ fn process_single_file_lint( println!("{}", diagnostics.to_human_readable()); } - // Exit with non-zero code if there are errors + // Return error if there are diagnostics errors if diagnostics.has_errors() { - std::process::exit(1); + return Err(anyhow::anyhow!("Diagnostics found errors in file")); } Ok(())