From ed7580ad223b0ce6d0e9bcad2bad2db456eba1d9 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 15 Jul 2020 13:54:45 +0300 Subject: [PATCH] app/vmalert: consistently use "%w" instead of "%s" in `fmt.Errorf` when wrapping errors --- app/vmalert/remotewrite/remotewrite.go | 4 ++-- app/vmalert/remotewrite/remotewrite_test.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/vmalert/remotewrite/remotewrite.go b/app/vmalert/remotewrite/remotewrite.go index caff50a5c..c51be5168 100644 --- a/app/vmalert/remotewrite/remotewrite.go +++ b/app/vmalert/remotewrite/remotewrite.go @@ -226,14 +226,14 @@ func (c *Client) send(ctx context.Context, data []byte) error { r := bytes.NewReader(data) req, err := http.NewRequest("POST", c.addr, r) if err != nil { - return fmt.Errorf("failed to create new HTTP request: %s", err) + return fmt.Errorf("failed to create new HTTP request: %w", err) } if c.baPass != "" { req.SetBasicAuth(c.baUser, c.baPass) } resp, err := c.c.Do(req.WithContext(ctx)) if err != nil { - return fmt.Errorf("error while sending request to %s: %s; Data len %d(%d)", + return fmt.Errorf("error while sending request to %s: %w; Data len %d(%d)", req.URL, err, len(data), r.Size()) } defer func() { _ = resp.Body.Close() }() diff --git a/app/vmalert/remotewrite/remotewrite_test.go b/app/vmalert/remotewrite/remotewrite_test.go index 7dab24712..18a9cfff6 100644 --- a/app/vmalert/remotewrite/remotewrite_test.go +++ b/app/vmalert/remotewrite/remotewrite_test.go @@ -82,19 +82,19 @@ func (rw *rwServer) handler(w http.ResponseWriter, r *http.Request) { } data, err := ioutil.ReadAll(r.Body) if err != nil { - rw.err(w, fmt.Errorf("body read err: %s", err)) + rw.err(w, fmt.Errorf("body read err: %w", err)) return } defer func() { _ = r.Body.Close() }() b, err := snappy.Decode(nil, data) if err != nil { - rw.err(w, fmt.Errorf("decode err: %s", err)) + rw.err(w, fmt.Errorf("decode err: %w", err)) return } wr := &prompb.WriteRequest{} if err := wr.Unmarshal(b); err != nil { - rw.err(w, fmt.Errorf("unmarhsal err: %s", err)) + rw.err(w, fmt.Errorf("unmarhsal err: %w", err)) return } atomic.AddUint64(&rw.acceptedRows, uint64(len(wr.Timeseries)))