From def3236645d984f14d5a0d7b50d8ecdb63a4c0c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Sat, 11 Aug 2018 22:54:45 +0100 Subject: [PATCH] fix(style): check of WriteString error return --- internal/models/alertgroup.go | 20 +++++++++++++++++--- internal/transform/colors.go | 15 +++++++++++++-- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/internal/models/alertgroup.go b/internal/models/alertgroup.go index c9703dd59..70439d641 100644 --- a/internal/models/alertgroup.go +++ b/internal/models/alertgroup.go @@ -6,6 +6,8 @@ import ( "io" "github.com/cnf/structhash" + + log "github.com/sirupsen/logrus" ) // AlertList is flat list of UnseeAlert objects @@ -46,8 +48,17 @@ type AlertGroup struct { // it should be unique for each AlertGroup func (ag AlertGroup) LabelsFingerprint() string { agIDHasher := sha1.New() - io.WriteString(agIDHasher, ag.Receiver) - io.WriteString(agIDHasher, fmt.Sprintf("%x", structhash.Sha1(ag.Labels, 1))) + + _, err := io.WriteString(agIDHasher, ag.Receiver) + if err != nil { + log.Errorf("Failed to write receiver value to alertgroup '%s' fingerprint: %s", ag.ID, err) + } + + _, err = io.WriteString(agIDHasher, fmt.Sprintf("%x", structhash.Sha1(ag.Labels, 1))) + if err != nil { + log.Errorf("Failed to write labels sha1 value to alertgroup '%s' fingerprint: %s", ag.ID, err) + } + return fmt.Sprintf("%x", agIDHasher.Sum(nil)) } @@ -55,7 +66,10 @@ func (ag AlertGroup) LabelsFingerprint() string { func (ag AlertGroup) ContentFingerprint() string { h := sha1.New() for _, alert := range ag.Alerts { - io.WriteString(h, alert.ContentFingerprint()) + _, err := io.WriteString(h, alert.ContentFingerprint()) + if err != nil { + log.Errorf("Failed to write alert fingerprint value to alertgroup '%s' fingerprint: %s", ag.ID, err) + } } return fmt.Sprintf("%x", h.Sum(nil)) } diff --git a/internal/transform/colors.go b/internal/transform/colors.go index 5b70bf02c..c88e997f7 100644 --- a/internal/transform/colors.go +++ b/internal/transform/colors.go @@ -10,12 +10,23 @@ import ( "github.com/prymitive/unsee/internal/slices" "github.com/hansrodtang/randomcolor" + + log "github.com/sirupsen/logrus" ) func labelToSeed(key string, val string) int64 { h := sha1.New() - io.WriteString(h, key) - io.WriteString(h, val) + + _, err := io.WriteString(h, key) + if err != nil { + log.Errorf("Failed to write label key '%s' to the seed sha1: %s", key, err) + } + + _, err = io.WriteString(h, val) + if err != nil { + log.Errorf("Failed to write label value '%s' to the seed sha1: %s", val, err) + } + var seed int64 for _, i := range h.Sum(nil) { seed += int64(i)