From 41ff4b323e9c1be314215d8a4e34dfa5e6055e57 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sun, 9 Jun 2019 09:33:54 +0200 Subject: [PATCH] lib/api: Correct logic for errors.jons in support bundle (fixes #5766) The err check should always be done with != and have the error case first, to follow the pattern and avoid mistakes like these. --- lib/api/api.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/api/api.go b/lib/api/api.go index eb4c415e..9198a04c 100644 --- a/lib/api/api.go +++ b/lib/api/api.go @@ -961,10 +961,10 @@ func (s *service) getSupportBundle(w http.ResponseWriter, r *http.Request) { var files []fileEntry // Redacted configuration as a JSON - if jsonConfig, err := json.MarshalIndent(getRedactedConfig(s), "", " "); err == nil { - files = append(files, fileEntry{name: "config.json.txt", data: jsonConfig}) - } else { + if jsonConfig, err := json.MarshalIndent(getRedactedConfig(s), "", " "); err != nil { l.Warnln("Support bundle: failed to create config.json:", err) + } else { + files = append(files, fileEntry{name: "config.json.txt", data: jsonConfig}) } // Log as a text @@ -977,9 +977,9 @@ func (s *service) getSupportBundle(w http.ResponseWriter, r *http.Request) { // Errors as a JSON if errs := s.guiErrors.Since(time.Time{}); len(errs) > 0 { if jsonError, err := json.MarshalIndent(errs, "", " "); err != nil { - files = append(files, fileEntry{name: "errors.json.txt", data: jsonError}) - } else { l.Warnln("Support bundle: failed to create errors.json:", err) + } else { + files = append(files, fileEntry{name: "errors.json.txt", data: jsonError}) } }