From 0c42d1533dd205d1e45d730a1208456dafd3adb4 Mon Sep 17 00:00:00 2001 From: igorfraa Date: Fri, 27 Sep 2024 16:13:08 +0300 Subject: [PATCH] Use %w in fmt.Errorf() to avoid context loss Signed-off-by: igorfraa --- prom2json.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/prom2json.go b/prom2json.go index c0d99699..bcdddd56 100644 --- a/prom2json.go +++ b/prom2json.go @@ -179,14 +179,14 @@ func FetchMetricFamilies(url string, ch chan<- *dto.MetricFamily, transport http req, err := http.NewRequest("GET", url, nil) if err != nil { close(ch) - return fmt.Errorf("creating GET request for URL %q failed: %v", url, err) + return fmt.Errorf("creating GET request for URL %q failed: %w", url, err) } req.Header.Add("Accept", acceptHeader) client := http.Client{Transport: transport} resp, err := client.Do(req) if err != nil { close(ch) - return fmt.Errorf("executing GET request for URL %q failed: %v", url, err) + return fmt.Errorf("executing GET request for URL %q failed: %w", url, err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { @@ -211,7 +211,7 @@ func ParseResponse(resp *http.Response, ch chan<- *dto.MetricFamily) error { if err == io.EOF { break } - return fmt.Errorf("reading metric family protocol buffer failed: %v", err) + return fmt.Errorf("reading metric family protocol buffer failed: %w", err) } ch <- mf }