From 53a7f0fa490d834185a7dd27331ae232b0e651aa Mon Sep 17 00:00:00 2001 From: Sarthak Negi <122533767+sarthaksarthak9@users.noreply.github.com> Date: Wed, 11 Oct 2023 20:04:27 +0530 Subject: [PATCH] :bug: Handle file writing errors as fatal errors (#367) Closes #314 --------- Signed-off-by: sarthaksarthak9 --- cmd/analyzer/main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/analyzer/main.go b/cmd/analyzer/main.go index df0ce74f..1dca5d7f 100644 --- a/cmd/analyzer/main.go +++ b/cmd/analyzer/main.go @@ -213,7 +213,11 @@ func main() { os.Exit(EXIT_ON_ERROR_CODE) } - os.WriteFile(outputViolations, b, 0644) + err = os.WriteFile(outputViolations, b, 0644) + if err != nil { + log.Error(err, "error writing output file", "file", outputViolations) + os.Exit(1) // Treat the error as a fatal error + } } func validateFlags() error {