Skip to content

Commit

Permalink
Use %w in fmt.Errorf() to avoid context loss
Browse files Browse the repository at this point in the history
Signed-off-by: igorfraa <[email protected]>
  • Loading branch information
igorfraa authored Sep 27, 2024
1 parent e76e848 commit 0c42d15
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions prom2json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit 0c42d15

Please sign in to comment.