From 0ba14600daf10a22cce9a257596979ee0070d86c Mon Sep 17 00:00:00 2001 From: Alan Bernstein Date: Thu, 10 May 2018 12:08:46 -0500 Subject: [PATCH] Wrap a few more errors --- broadcast.go | 5 +++-- diagnostics.go | 8 +++++--- gossip/gossip.go | 2 +- server.go | 2 +- uri.go | 4 ++-- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/broadcast.go b/broadcast.go index de43f3b85..2be5e08db 100644 --- a/broadcast.go +++ b/broadcast.go @@ -20,6 +20,7 @@ import ( "github.com/gogo/protobuf/proto" "github.com/pilosa/pilosa/internal" + "github.com/pkg/errors" ) // MemberSet represents an interface for Node membership and inter-node communication. @@ -187,7 +188,7 @@ func MarshalMessage(m proto.Message) ([]byte, error) { } buf, err := proto.Marshal(m) if err != nil { - return nil, err + return nil, errors.Wrap(err, "marshalling") } return append([]byte{typ}, buf...), nil } @@ -241,7 +242,7 @@ func UnmarshalMessage(buf []byte) (proto.Message, error) { } if err := proto.Unmarshal(buf, m); err != nil { - return nil, err + return nil, errors.Wrap(err, "unmarshalling") } return m, nil } diff --git a/diagnostics.go b/diagnostics.go index bfebbb495..46ffc2110 100644 --- a/diagnostics.go +++ b/diagnostics.go @@ -23,6 +23,8 @@ import ( "strings" "sync" "time" + + "github.com/pkg/errors" ) // Default version check URL. @@ -80,13 +82,13 @@ func (d *DiagnosticsCollector) Flush() error { d.metrics["Uptime"] = (time.Now().Unix() - d.startTime) buf, err := d.encode() if err != nil { - return err + return errors.Wrap(err, "encoding") } req, err := http.NewRequest("POST", d.host, bytes.NewReader(buf)) req.Header.Set("Content-Type", "application/json") resp, err := d.client.Do(req) if err != nil { - return err + return errors.Wrap(err, "posting") } // Intentionally ignoring response body, as user does not need to be notified of error. defer resp.Body.Close() @@ -99,7 +101,7 @@ func (d *DiagnosticsCollector) CheckVersion() error { req, err := http.NewRequest("GET", d.VersionURL, nil) resp, err := d.client.Do(req) if err != nil { - return err + return errors.Wrap(err, "getting version") } defer resp.Body.Close() diff --git a/gossip/gossip.go b/gossip/gossip.go index 49b66d8a2..2da6e3e4c 100644 --- a/gossip/gossip.go +++ b/gossip/gossip.go @@ -176,7 +176,7 @@ func NewGossipMemberSet(name string, host string, cfg Config, ger *GossipEventRe // options for _, opt := range options { if err := opt(g); err != nil { - return nil, err + return nil, errors.Wrap(err, "executing option") } } diff --git a/server.go b/server.go index c8b631580..e739fe5f0 100644 --- a/server.go +++ b/server.go @@ -629,7 +629,7 @@ func (s *Server) mergeRemoteStatus(ns *internal.NodeStatus) error { // Sync schema. if err := s.Holder.ApplySchema(ns.Schema); err != nil { - return err + return errors.Wrap(err, "applying schema") } // Sync maxSlices (standard). diff --git a/uri.go b/uri.go index beb5060b5..dfb82baef 100644 --- a/uri.go +++ b/uri.go @@ -16,13 +16,13 @@ package pilosa import ( "encoding/json" - "errors" "fmt" "regexp" "strconv" "strings" "github.com/pilosa/pilosa/internal" + "github.com/pkg/errors" ) var schemeRegexp = regexp.MustCompile("^[+a-z]+$") @@ -72,7 +72,7 @@ func NewURIFromHostPort(host string, port uint16) (*URI, error) { uri := DefaultURI() err := uri.SetHost(host) if err != nil { - return nil, err + return nil, errors.Wrap(err, "setting uri host") } uri.SetPort(port) return uri, nil