Skip to content

Commit

Permalink
chore: wrap strings in error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
nilic committed Nov 9, 2023
1 parent 9073109 commit 52809c8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/hntop/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func newApp() *cli.App {
tags := strings.Split(s, ",")
for _, t := range tags {
if !slices.Contains(availableTags, t) {
return fmt.Errorf(`invalid tag value "%s", available tags: %v`, t, availableTags)
return fmt.Errorf("invalid tag value %q, available tags: %v", t, availableTags)
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/hntop/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func output(cCtx *cli.Context, q *htclient.Query, h *htclient.Hits) error {

return nil
default:
return fmt.Errorf("unknown output type: %s", cCtx.String("output"))
return fmt.Errorf("unknown output type: %q", cCtx.String("output"))
}
}

Expand Down
10 changes: 5 additions & 5 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Client struct {
func NewClient(URL, userAgent string) (*Client, error) {
u, err := url.Parse(URL)
if err != nil {
return nil, fmt.Errorf("parsing URL %s: %w", URL, err)
return nil, fmt.Errorf("parsing URL %q: %w", URL, err)
}

c := &Client{
Expand All @@ -36,7 +36,7 @@ func NewClient(URL, userAgent string) (*Client, error) {
func (c *Client) NewRequest(httpMethod string, headers map[string]string, body io.Reader) (*http.Request, error) {
regex := regexp.MustCompile(`^(GET|POST|PUT|PATCH|DELETE)$`)
if !regex.MatchString(httpMethod) {
return nil, fmt.Errorf("invalid HTTP method: %s", httpMethod)
return nil, fmt.Errorf("invalid HTTP method: %q", httpMethod)
}

req, err := http.NewRequest(httpMethod, c.URL.String(), body)
Expand All @@ -62,7 +62,7 @@ func (c *Client) Do(req *http.Request, v any) error {
}

if res == nil {
return fmt.Errorf("empty response from %s", req.URL.RequestURI())
return fmt.Errorf("empty response from %q", req.URL.RequestURI())
}

responseBody, err := io.ReadAll(res.Body)
Expand All @@ -73,13 +73,13 @@ func (c *Client) Do(req *http.Request, v any) error {
defer res.Body.Close()

if res.StatusCode != http.StatusOK {
return fmt.Errorf("calling %s:\nstatus: %s\nresponseData: %s", req.URL.RequestURI(), res.Status, responseBody)
return fmt.Errorf("calling %q:\nstatus: %q\nresponseData: %q", req.URL.RequestURI(), res.Status, responseBody)
}

err = json.Unmarshal(responseBody, v)

if err != nil {
return fmt.Errorf("reading response from %s %s: %w", req.Method, req.URL.RequestURI(), err)
return fmt.Errorf(`reading response from "%s %s": %w`, req.Method, req.URL.RequestURI(), err)
}

return nil
Expand Down

0 comments on commit 52809c8

Please sign in to comment.