diff --git a/client/client.go b/client/client.go index 64367931e9f..9c5f56c8fc3 100644 --- a/client/client.go +++ b/client/client.go @@ -82,7 +82,7 @@ func (p *Client) Post(query string, response interface{}, options ...Option) err func (p *Client) RawPost(query string, options ...Option) (*Response, error) { r, err := p.newRequest(query, options...) if err != nil { - return nil, fmt.Errorf("build: %s", err.Error()) + return nil, fmt.Errorf("build: %w", err) } w := httptest.NewRecorder() @@ -97,7 +97,7 @@ func (p *Client) RawPost(query string, options ...Option) (*Response, error) { respDataRaw := &Response{} err = json.Unmarshal(w.Body.Bytes(), &respDataRaw) if err != nil { - return nil, fmt.Errorf("decode: %s", err.Error()) + return nil, fmt.Errorf("decode: %w", err) } return respDataRaw, nil @@ -123,7 +123,7 @@ func (p *Client) newRequest(query string, options ...Option) (*http.Request, err case "application/json": requestBody, err := json.Marshal(bd) if err != nil { - return nil, fmt.Errorf("encode: %s", err.Error()) + return nil, fmt.Errorf("encode: %w", err) } bd.HTTP.Body = ioutil.NopCloser(bytes.NewBuffer(requestBody)) default: @@ -141,7 +141,7 @@ func unpack(data interface{}, into interface{}) error { ZeroFields: true, }) if err != nil { - return fmt.Errorf("mapstructure: %s", err.Error()) + return fmt.Errorf("mapstructure: %w", err) } return d.Decode(data) diff --git a/client/websocket.go b/client/websocket.go index 35c74dddcd3..ca6ee7c4723 100644 --- a/client/websocket.go +++ b/client/websocket.go @@ -53,12 +53,12 @@ func (p *Client) WebsocketOnce(query string, resp interface{}, options ...Option func (p *Client) WebsocketWithPayload(query string, initPayload map[string]interface{}, options ...Option) *Subscription { r, err := p.newRequest(query, options...) if err != nil { - return errorSubscription(fmt.Errorf("request: %s", err.Error())) + return errorSubscription(fmt.Errorf("request: %w", err)) } requestBody, err := ioutil.ReadAll(r.Body) if err != nil { - return errorSubscription(fmt.Errorf("parse body: %s", err.Error())) + return errorSubscription(fmt.Errorf("parse body: %w", err)) } srv := httptest.NewServer(p.h) @@ -66,24 +66,24 @@ func (p *Client) WebsocketWithPayload(query string, initPayload map[string]inter c, _, err := websocket.DefaultDialer.Dial(host+r.URL.Path, r.Header) if err != nil { - return errorSubscription(fmt.Errorf("dial: %s", err.Error())) + return errorSubscription(fmt.Errorf("dial: %w", err)) } initMessage := operationMessage{Type: connectionInitMsg} if initPayload != nil { initMessage.Payload, err = json.Marshal(initPayload) if err != nil { - return errorSubscription(fmt.Errorf("parse payload: %s", err.Error())) + return errorSubscription(fmt.Errorf("parse payload: %w", err)) } } if err = c.WriteJSON(initMessage); err != nil { - return errorSubscription(fmt.Errorf("init: %s", err.Error())) + return errorSubscription(fmt.Errorf("init: %w", err)) } var ack operationMessage if err = c.ReadJSON(&ack); err != nil { - return errorSubscription(fmt.Errorf("ack: %s", err.Error())) + return errorSubscription(fmt.Errorf("ack: %w", err)) } if ack.Type != connectionAckMsg { @@ -92,7 +92,7 @@ func (p *Client) WebsocketWithPayload(query string, initPayload map[string]inter var ka operationMessage if err = c.ReadJSON(&ka); err != nil { - return errorSubscription(fmt.Errorf("ack: %s", err.Error())) + return errorSubscription(fmt.Errorf("ack: %w", err)) } if ka.Type != connectionKaMsg { @@ -100,7 +100,7 @@ func (p *Client) WebsocketWithPayload(query string, initPayload map[string]inter } if err = c.WriteJSON(operationMessage{Type: startMsg, ID: "1", Payload: requestBody}); err != nil { - return errorSubscription(fmt.Errorf("start: %s", err.Error())) + return errorSubscription(fmt.Errorf("start: %w", err)) } return &Subscription{ @@ -125,7 +125,7 @@ func (p *Client) WebsocketWithPayload(query string, initPayload map[string]inter var respDataRaw Response err = json.Unmarshal(op.Payload, &respDataRaw) if err != nil { - return fmt.Errorf("decode: %s", err.Error()) + return fmt.Errorf("decode: %w", err) } // we want to unpack even if there is an error, so we can see partial responses diff --git a/internal/rewrite/rewriter.go b/internal/rewrite/rewriter.go index 1b9adb171ee..f70fbdc1d59 100644 --- a/internal/rewrite/rewriter.go +++ b/internal/rewrite/rewriter.go @@ -58,7 +58,7 @@ func (r *Rewriter) getFile(filename string) string { if _, ok := r.files[filename]; !ok { b, err := ioutil.ReadFile(filename) if err != nil { - panic(fmt.Errorf("unable to load file, already exists: %s", err.Error())) + panic(fmt.Errorf("unable to load file, already exists: %w", err)) } r.files[filename] = string(b)