From 9ea67b35543127ff70f1fb5d8992542cb3d90d14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Musab=20G=C3=BCltekin?= Date: Sat, 17 Apr 2021 11:11:29 +0300 Subject: [PATCH] Use fmt.Errorf instead of errors package. This is good convention after go 1.13 --- client/client.go | 18 ++++++++++-------- go.mod | 1 - go.sum | 2 -- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/client/client.go b/client/client.go index 4ea3d86..48d75e0 100644 --- a/client/client.go +++ b/client/client.go @@ -2,11 +2,12 @@ package client import ( "context" + "errors" + "fmt" "github.com/chromedp/cdproto/dom" "github.com/chromedp/cdproto/network" "github.com/chromedp/chromedp" "github.com/geziyor/geziyor/internal" - "github.com/pkg/errors" "golang.org/x/net/html/charset" "golang.org/x/text/transform" "io" @@ -101,7 +102,7 @@ func (c *Client) DoRequest(req *Request) (resp *Response, err error) { internal.Logger.Println("Retrying:", req.URL.String()) return c.DoRequest(req) } - return resp, errors.Wrap(err, "Response error") + return resp, err } // Retry on http status codes @@ -124,7 +125,7 @@ func (c *Client) doRequestClient(req *Request) (*Response, error) { defer resp.Body.Close() } if err != nil { - return nil, err + return nil, fmt.Errorf("response: %w", err) } // Limit response body reading @@ -138,9 +139,10 @@ func (c *Client) doRequestClient(req *Request) (*Response, error) { } } else { if !c.opt.CharsetDetectDisabled { - bodyReader, err = charset.NewReader(bodyReader, req.Header.Get("Content-Type")) + contentType := req.Header.Get("Content-Type") + bodyReader, err = charset.NewReader(bodyReader, contentType) if err != nil { - return nil, errors.Wrap(err, "Reading determined encoding error") + return nil, fmt.Errorf("charset detection error on content-type %s: %w", contentType, err) } } } @@ -148,7 +150,7 @@ func (c *Client) doRequestClient(req *Request) (*Response, error) { body, err := ioutil.ReadAll(bodyReader) if err != nil { - return nil, errors.Wrap(err, "Reading body error") + return nil, fmt.Errorf("reading body: %w", err) } response := Response{ @@ -211,7 +213,7 @@ func (c *Client) doRequestChrome(req *Request) (*Response, error) { return err }), ); err != nil { - return nil, errors.Wrap(err, "Request getting rendered error") + return nil, fmt.Errorf("request getting rendered: %w", err) } // Update changed data @@ -289,7 +291,7 @@ func ConvertMapToHeader(m map[string]interface{}) http.Header { func NewRedirectionHandler(maxRedirect int) func(req *http.Request, via []*http.Request) error { return func(req *http.Request, via []*http.Request) error { if len(via) >= maxRedirect { - return errors.Errorf("stopped after %d redirects", maxRedirect) + return fmt.Errorf("stopped after %d redirects", maxRedirect) } return nil } diff --git a/go.mod b/go.mod index c2a48ac..0aac551 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,6 @@ require ( github.com/go-kit/kit v0.8.0 github.com/google/btree v1.0.0 // indirect github.com/peterbourgon/diskv v2.0.1+incompatible - github.com/pkg/errors v0.8.1 github.com/prometheus/client_golang v1.0.0 github.com/stretchr/testify v1.3.0 github.com/syndtr/goleveldb v1.0.0 diff --git a/go.sum b/go.sum index bf67660..8c60267 100644 --- a/go.sum +++ b/go.sum @@ -63,8 +63,6 @@ github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=