nff: handle errors and exit appropriately in linter
This commit is contained in:
parent
16586e9927
commit
0ed74c6a51
1 changed files with 10 additions and 2 deletions
12
src/main.rs
12
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(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue