From 046e96cfecec1bc126c4b263775432ec730c030f Mon Sep 17 00:00:00 2001 From: Bernhard Reiter Date: Tue, 10 May 2022 16:46:32 +0200 Subject: [PATCH] Improve exit code for failed upload * Add an exit code if an upload failed, but also print all the messages as before. --- cmd/csaf_uploader/main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/csaf_uploader/main.go b/cmd/csaf_uploader/main.go index dcee311..01dc937 100644 --- a/cmd/csaf_uploader/main.go +++ b/cmd/csaf_uploader/main.go @@ -288,8 +288,11 @@ func (p *processor) process(filename string) error { } defer resp.Body.Close() + var uploadErr error if resp.StatusCode != http.StatusOK { - log.Printf("Upload failed: %s\n", resp.Status) + s := fmt.Sprintf("upload failed: %s", resp.Status) + fmt.Printf("HTTPS %s\n", s) + uploadErr = errors.New(s) } var result struct { @@ -313,7 +316,7 @@ func (p *processor) process(filename string) error { writeStrings("Warnings:", result.Warnings) writeStrings("Errors:", result.Errors) - return nil + return uploadErr } // findIniFile looks for a file in the pre-defined paths in "iniPaths".