From 52809c86699e2352feaeb4396ca78aecb5ae5f07 Mon Sep 17 00:00:00 2001 From: nilic Date: Thu, 9 Nov 2023 22:21:02 +0100 Subject: [PATCH] chore: wrap strings in error messages --- cmd/hntop/app.go | 2 +- cmd/hntop/output.go | 2 +- internal/client/client.go | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/hntop/app.go b/cmd/hntop/app.go index 96e61fe..d639f3e 100644 --- a/cmd/hntop/app.go +++ b/cmd/hntop/app.go @@ -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 diff --git a/cmd/hntop/output.go b/cmd/hntop/output.go index 8dc646f..c82930f 100644 --- a/cmd/hntop/output.go +++ b/cmd/hntop/output.go @@ -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")) } } diff --git a/internal/client/client.go b/internal/client/client.go index 030ed17..47633c8 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -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{ @@ -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) @@ -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) @@ -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