mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
all: remove pkg/errors
This commit is contained in:
committed by
Ariel Mashraki
parent
f0710aa004
commit
eb87d64980
@@ -5,10 +5,10 @@
|
||||
package graphson
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// EncoderOfError returns a value encoder which always fails to encode.
|
||||
@@ -22,7 +22,7 @@ func (decodeExtension) DecoderOfError(format string, args ...interface{}) jsonit
|
||||
}
|
||||
|
||||
func decoratorOfError(format string, args ...interface{}) errorCodec {
|
||||
err := errors.Errorf(format, args...)
|
||||
err := fmt.Errorf(format, args...)
|
||||
return errorCodec{err}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ package graphson
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
@@ -13,7 +14,6 @@ import (
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/modern-go/reflect2"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// DecoratorOfInterface decorates a value decoder of an interface type.
|
||||
@@ -122,7 +122,7 @@ func (efaceDecoder) reflectType(typ Type) reflect2.Type {
|
||||
func (efaceDecoder) reflectSlice(data []byte) (reflect2.Type, error) {
|
||||
var elem interface{}
|
||||
if err := Unmarshal(data, &[...]*interface{}{&elem}); err != nil {
|
||||
return nil, errors.Wrap(err, "cannot read first list element")
|
||||
return nil, fmt.Errorf("cannot read first list element: %w", err)
|
||||
}
|
||||
|
||||
if elem == nil {
|
||||
@@ -139,7 +139,7 @@ func (efaceDecoder) reflectMap(data []byte) (reflect2.Type, error) {
|
||||
bytes.Replace(data, []byte(mapType), []byte(listType), 1),
|
||||
&[...]*interface{}{&key, &elem},
|
||||
); err != nil {
|
||||
return nil, errors.Wrap(err, "cannot unmarshal first map item")
|
||||
return nil, fmt.Errorf("cannot unmarshal first map item: %w", err)
|
||||
}
|
||||
|
||||
if key == nil {
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
package graphson
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"unsafe"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/modern-go/reflect2"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// LazyEncoderOf returns a lazy encoder for type.
|
||||
@@ -68,7 +68,7 @@ type uniqueType struct {
|
||||
func (u *uniqueType) CheckType(other Type) error {
|
||||
u.once.Do(func() { u.typ = other })
|
||||
if u.typ != other {
|
||||
return errors.Errorf("expect type %s, but found %s", u.typ, other)
|
||||
return fmt.Errorf("expect type %s, but found %s", u.typ, other)
|
||||
}
|
||||
return u.elemChecker.CheckType(u.typ)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/modern-go/reflect2"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// DecoratorOfMarshaler decorates a value encoder of a Marshaler interface.
|
||||
@@ -69,11 +68,11 @@ func (enc marshalerEncoder) Encode(ptr unsafe.Pointer, stream *jsoniter.Stream)
|
||||
func (enc marshalerEncoder) encode(marshaler Marshaler, stream *jsoniter.Stream) {
|
||||
data, err := marshaler.MarshalGraphson()
|
||||
if err != nil {
|
||||
stream.Error = errors.Wrapf(err, "graphson: error calling MarshalGraphson for type %s", enc.Type)
|
||||
stream.Error = fmt.Errorf("graphson: error calling MarshalGraphson for type %s: %w", enc.Type, err)
|
||||
return
|
||||
}
|
||||
if !config.Valid(data) {
|
||||
stream.Error = errors.Errorf("graphson: syntax error when marshaling type %s", enc.Type)
|
||||
stream.Error = fmt.Errorf("graphson: syntax error when marshaling type %s", enc.Type)
|
||||
return
|
||||
}
|
||||
_, stream.Error = stream.Write(data)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
package graphson
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// RawMessage is a raw encoded graphson value.
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
package graphson
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
"unsafe"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/modern-go/reflect2"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// DecoratorOfSlice decorates a value encoder of a slice type.
|
||||
@@ -87,7 +87,7 @@ type sliceDecoder struct {
|
||||
func (dec sliceDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) {
|
||||
dec.decode(ptr, iter)
|
||||
if iter.Error != nil && iter.Error != io.EOF {
|
||||
iter.Error = errors.Wrapf(iter.Error, "decoding slice %s", dec.sliceType)
|
||||
iter.Error = fmt.Errorf("decoding slice %s: %w", dec.sliceType, iter.Error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ type arrayDecoder struct {
|
||||
func (dec arrayDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) {
|
||||
dec.decode(ptr, iter)
|
||||
if iter.Error != nil && iter.Error != io.EOF {
|
||||
iter.Error = errors.Wrapf(iter.Error, "decoding array %s", dec.arrayType)
|
||||
iter.Error = fmt.Errorf("decoding array %s: %w", dec.arrayType, iter.Error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
package graphson
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"unsafe"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/modern-go/reflect2"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// A Type is a graphson type.
|
||||
@@ -45,7 +45,7 @@ func (typ Type) String() string {
|
||||
// CheckType implements typeChecker interface.
|
||||
func (typ Type) CheckType(other Type) error {
|
||||
if typ != other {
|
||||
return errors.Errorf("expect type %s, but found %s", typ, other)
|
||||
return fmt.Errorf("expect type %s, but found %s", typ, other)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -80,7 +80,7 @@ func (types Types) String() string {
|
||||
// CheckType implements typeChecker interface.
|
||||
func (types Types) CheckType(typ Type) error {
|
||||
if !types.Contains(typ) {
|
||||
return errors.Errorf("expect any of %s, but found %s", types, typ)
|
||||
return fmt.Errorf("expect any of %s, but found %s", types, typ)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
package graphson
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"unsafe"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// graphson encoding type / value keys
|
||||
|
||||
@@ -6,11 +6,11 @@ package gremlin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// ExpandBindings expands the given RoundTripper and expands the request bindings into the Gremlin traversal.
|
||||
@@ -35,7 +35,7 @@ func ExpandBindings(rt RoundTripper) RoundTripper {
|
||||
for _, k := range keys {
|
||||
s, err := jsoniter.MarshalToString(bindings[k])
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "marshal bindings value for key %s", k)
|
||||
return nil, fmt.Errorf("marshal bindings value for key %s: %w", k, err)
|
||||
}
|
||||
kv = append(kv, k, s)
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@ import (
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/gremlin/encoding/graphson"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -58,7 +56,7 @@ func (e Edge) MarshalGraphson() ([]byte, error) {
|
||||
func (e *Edge) UnmarshalGraphson(data []byte) error {
|
||||
var edge edge
|
||||
if err := graphson.Unmarshal(data, &edge); err != nil {
|
||||
return errors.Wrap(err, "unmarshaling edge")
|
||||
return fmt.Errorf("unmarshaling edge: %w", err)
|
||||
}
|
||||
|
||||
*e = NewEdge(
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
package graph
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// ValueMap models a .valueMap() gremlin response.
|
||||
@@ -47,10 +48,10 @@ func (m ValueMap) decode(v interface{}) error {
|
||||
|
||||
dec, err := mapstructure.NewDecoder(&cfg)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "creating structure decoder")
|
||||
return fmt.Errorf("creating structure decoder: %w", err)
|
||||
}
|
||||
if err := dec.Decode(m); err != nil {
|
||||
return errors.Wrap(err, "decoding value map")
|
||||
return fmt.Errorf("decoding value map: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ package gremlin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@@ -14,7 +16,6 @@ import (
|
||||
"entgo.io/ent/dialect/gremlin/encoding/graphson"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type httpTransport struct {
|
||||
@@ -26,7 +27,7 @@ type httpTransport struct {
|
||||
func NewHTTPTransport(urlStr string, client *http.Client) (RoundTripper, error) {
|
||||
u, err := url.Parse(urlStr)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "gremlin/http: parsing url")
|
||||
return nil, fmt.Errorf("gremlin/http: parsing url: %w", err)
|
||||
}
|
||||
if client == nil {
|
||||
client = http.DefaultClient
|
||||
@@ -37,7 +38,7 @@ func NewHTTPTransport(urlStr string, client *http.Client) (RoundTripper, error)
|
||||
// RoundTrip implements RouterTripper interface.
|
||||
func (t *httpTransport) RoundTrip(ctx context.Context, req *Request) (*Response, error) {
|
||||
if req.Operation != OpsEval {
|
||||
return nil, errors.Errorf("gremlin/http: unsupported operation: %q", req.Operation)
|
||||
return nil, fmt.Errorf("gremlin/http: unsupported operation: %q", req.Operation)
|
||||
}
|
||||
if _, ok := req.Arguments[ArgsGremlin]; !ok {
|
||||
return nil, errors.New("gremlin/http: missing query expression")
|
||||
@@ -47,26 +48,29 @@ func (t *httpTransport) RoundTrip(ctx context.Context, req *Request) (*Response,
|
||||
defer pr.Close()
|
||||
go func() {
|
||||
err := jsoniter.NewEncoder(pw).Encode(req.Arguments)
|
||||
_ = pw.CloseWithError(errors.Wrap(err, "gremlin/http: encoding request"))
|
||||
if err != nil {
|
||||
err = fmt.Errorf("gremlin/http: encoding request: %w", err)
|
||||
}
|
||||
_ = pw.CloseWithError(err)
|
||||
}()
|
||||
|
||||
var br io.Reader
|
||||
{
|
||||
req, err := http.NewRequest(http.MethodPost, t.url, pr)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "gremlin/http: creating http request")
|
||||
return nil, fmt.Errorf("gremlin/http: creating http request: %w", err)
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
rsp, err := t.client.Do(req.WithContext(ctx))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "gremlin/http: posting http request")
|
||||
return nil, fmt.Errorf("gremlin/http: posting http request: %w", err)
|
||||
}
|
||||
defer rsp.Body.Close()
|
||||
|
||||
if rsp.StatusCode < http.StatusOK || rsp.StatusCode > http.StatusPartialContent {
|
||||
body, _ := ioutil.ReadAll(rsp.Body)
|
||||
return nil, errors.Errorf("gremlin/http: status=%q, body=%q", rsp.Status, body)
|
||||
return nil, fmt.Errorf("gremlin/http: status=%q, body=%q", rsp.Status, body)
|
||||
}
|
||||
if rsp.ContentLength > MaxResponseSize {
|
||||
return nil, errors.New("gremlin/http: context length exceeds limit")
|
||||
@@ -76,7 +80,7 @@ func (t *httpTransport) RoundTrip(ctx context.Context, req *Request) (*Response,
|
||||
|
||||
var rsp Response
|
||||
if err := graphson.NewDecoder(io.LimitReader(br, MaxResponseSize)).Decode(&rsp); err != nil {
|
||||
return nil, errors.Wrap(err, "gremlin/http: decoding response")
|
||||
return nil, fmt.Errorf("gremlin/http: decoding response: %w", err)
|
||||
}
|
||||
return &rsp, nil
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ package ws
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"sync"
|
||||
@@ -17,7 +19,6 @@ import (
|
||||
"entgo.io/ent/dialect/gremlin/encoding/graphson"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
@@ -106,7 +107,7 @@ func (d *Dialer) Dial(uri string) (*Conn, error) {
|
||||
func (d *Dialer) DialContext(ctx context.Context, uri string) (*Conn, error) {
|
||||
c, rsp, err := d.Dialer.DialContext(ctx, uri, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "gremlin: dialing uri %s", uri)
|
||||
return nil, fmt.Errorf("gremlin: dialing uri %s: %w", uri, err)
|
||||
}
|
||||
defer rsp.Body.Close()
|
||||
|
||||
@@ -141,7 +142,7 @@ func (c *Conn) Execute(ctx context.Context, req *gremlin.Request) (*gremlin.Resp
|
||||
c.grp.Go(func() error {
|
||||
err := graphson.NewEncoder(pw).Encode(req)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "encoding request")
|
||||
err = fmt.Errorf("encoding request: %w", err)
|
||||
}
|
||||
pw.CloseWithError(err)
|
||||
return err
|
||||
@@ -189,22 +190,22 @@ func (c *Conn) sender() error {
|
||||
// fetch next message writer
|
||||
w, err := c.conn.NextWriter(websocket.BinaryMessage)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "getting message writer")
|
||||
return fmt.Errorf("getting message writer: %w", err)
|
||||
}
|
||||
|
||||
// write mime header
|
||||
if _, err := w.Write(encoding.GraphSON3Mime); err != nil {
|
||||
return errors.Wrap(err, "writing mime header")
|
||||
return fmt.Errorf("writing mime header: %w", err)
|
||||
}
|
||||
|
||||
// write request body
|
||||
if _, err := io.Copy(w, r); err != nil {
|
||||
return errors.Wrap(err, "writing request")
|
||||
return fmt.Errorf("writing request: %w", err)
|
||||
}
|
||||
|
||||
// finish message write
|
||||
if err := w.Close(); err != nil {
|
||||
return errors.Wrap(err, "closing message writer")
|
||||
return fmt.Errorf("closing message writer: %w", err)
|
||||
}
|
||||
case <-c.ctx.Done():
|
||||
// connection closing
|
||||
@@ -216,7 +217,7 @@ func (c *Conn) sender() error {
|
||||
case <-pinger.C:
|
||||
// periodic connection keepalive
|
||||
if err := c.conn.WriteControl(websocket.PingMessage, nil, time.Now().Add(writeWait)); err != nil {
|
||||
return errors.Wrap(err, "writing ping message")
|
||||
return fmt.Errorf("writing ping message: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -240,13 +241,13 @@ func (c *Conn) receiver() error {
|
||||
// rely on sender connection close during termination
|
||||
_, r, err := c.conn.NextReader()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "getting next reader")
|
||||
return fmt.Errorf("writing ping message: %w", err)
|
||||
}
|
||||
|
||||
// decode received response
|
||||
var rsp gremlin.Response
|
||||
if err := graphson.NewDecoder(r).Decode(&rsp); err != nil {
|
||||
return errors.Wrap(err, "reading response")
|
||||
return fmt.Errorf("reading response: %w", err)
|
||||
}
|
||||
|
||||
ifr, ok := c.inflight.Load(rsp.RequestID)
|
||||
@@ -277,7 +278,7 @@ func (c *Conn) receive(ifr *inflight, rsp *gremlin.Response) bool {
|
||||
// append received fragment
|
||||
var frag []graphson.RawMessage
|
||||
if err := graphson.Unmarshal(rsp.Result.Data, &frag); err != nil {
|
||||
result.err = errors.Wrap(err, "decoding response fragment")
|
||||
result.err = fmt.Errorf("decoding response fragment: %w", err)
|
||||
break
|
||||
}
|
||||
ifr.frags = append(ifr.frags, frag...)
|
||||
@@ -289,7 +290,7 @@ func (c *Conn) receive(ifr *inflight, rsp *gremlin.Response) bool {
|
||||
|
||||
// reassemble fragmented response
|
||||
if rsp.Result.Data, result.err = graphson.Marshal(ifr.frags); result.err != nil {
|
||||
result.err = errors.Wrap(result.err, "assembling fragmented response")
|
||||
result.err = fmt.Errorf("assembling fragmented response: %w", result.err)
|
||||
}
|
||||
case gremlin.StatusAuthenticate:
|
||||
// receiver should never block
|
||||
@@ -298,7 +299,7 @@ func (c *Conn) receive(ifr *inflight, rsp *gremlin.Response) bool {
|
||||
if err := graphson.NewEncoder(&buf).Encode(
|
||||
gremlin.NewAuthRequest(rsp.RequestID, c.user, c.pass),
|
||||
); err != nil {
|
||||
return errors.Wrap(err, "encoding auth request")
|
||||
return fmt.Errorf("encoding auth request: %w", err)
|
||||
}
|
||||
select {
|
||||
case c.send <- &buf:
|
||||
|
||||
@@ -7,10 +7,10 @@ package gremlin
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
package gremlin
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/gremlin/encoding/graphson"
|
||||
"entgo.io/ent/dialect/gremlin/graph"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// A Response models a response message received from the server.
|
||||
@@ -38,7 +39,7 @@ func (rsp *Response) IsErr() bool {
|
||||
// Err returns an error representing response status.
|
||||
func (rsp *Response) Err() error {
|
||||
if rsp.IsErr() {
|
||||
return errors.Errorf("gremlin: code=%d, message=%q", rsp.Status.Code, rsp.Status.Message)
|
||||
return fmt.Errorf("gremlin: code=%d, message=%q", rsp.Status.Code, rsp.Status.Message)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -49,7 +50,7 @@ func (rsp *Response) ReadVal(v interface{}) error {
|
||||
return err
|
||||
}
|
||||
if err := graphson.Unmarshal(rsp.Result.Data, v); err != nil {
|
||||
return errors.Wrapf(err, "gremlin: unmarshal response data: type=%T", v)
|
||||
return fmt.Errorf("gremlin: unmarshal response data: type=%T: %w", v, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user