From 046e96cfecec1bc126c4b263775432ec730c030f Mon Sep 17 00:00:00 2001 From: Bernhard Reiter Date: Tue, 10 May 2022 16:46:32 +0200 Subject: [PATCH 1/2] 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". From de872893f1288dc82893ddbfea6a9efc535327e0 Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Tue, 10 May 2022 16:54:58 +0200 Subject: [PATCH 2/2] simplified code --- cmd/csaf_uploader/main.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmd/csaf_uploader/main.go b/cmd/csaf_uploader/main.go index 01dc937..bca2b21 100644 --- a/cmd/csaf_uploader/main.go +++ b/cmd/csaf_uploader/main.go @@ -290,9 +290,8 @@ func (p *processor) process(filename string) error { var uploadErr error if resp.StatusCode != http.StatusOK { - s := fmt.Sprintf("upload failed: %s", resp.Status) - fmt.Printf("HTTPS %s\n", s) - uploadErr = errors.New(s) + uploadErr := fmt.Errorf("upload failed: %s", resp.Status) + fmt.Printf("HTTPS %s\n", uploadErr) } var result struct {