diff --git a/arrayiter/arrayiter.go b/arrayiter/arrayiter.go index 435cfa7..b531e76 100644 --- a/arrayiter/arrayiter.go +++ b/arrayiter/arrayiter.go @@ -2,10 +2,9 @@ package arrayiter import ( "context" + "fmt" "reflect" "sync" - - "github.com/pkg/errors" ) func Iterate(ctx context.Context, a interface{}) (Iterator, error) { @@ -14,7 +13,7 @@ func Iterate(ctx context.Context, a interface{}) (Iterator, error) { switch arv.Kind() { case reflect.Array, reflect.Slice: default: - return nil, errors.Errorf(`argument must be an array/slice (%s)`, arv.Type()) + return nil, fmt.Errorf(`argument must be an array/slice (%s)`, arv.Type()) } ch := make(chan *Pair) @@ -119,7 +118,7 @@ func Walk(ctx context.Context, s Source, v Visitor) error { for i := s.Iterate(ctx); i.Next(ctx); { pair := i.Pair() if err := v.Visit(pair.Index, pair.Value); err != nil { - return errors.Wrapf(err, `failed to visit index %d`, pair.Index) + return fmt.Errorf(`failed to visit index %d: %w`, pair.Index, err) } } return nil @@ -131,13 +130,13 @@ func AsArray(ctx context.Context, s interface{}, v interface{}) error { case reflect.Array, reflect.Slice: x, err := Iterate(ctx, s) if err != nil { - return errors.Wrap(err, `failed to iterate over array/slice type`) + return fmt.Errorf(`failed to iterate over array/slice type: %w`, err) } iter = x default: ssrc, ok := s.(Source) if !ok { - return errors.Errorf(`cannot iterate over %T: not a arrayiter.Source type`, s) + return fmt.Errorf(`cannot iterate over %T: not a arrayiter.Source type`, s) } iter = ssrc.Iterate(ctx) } @@ -146,14 +145,14 @@ func AsArray(ctx context.Context, s interface{}, v interface{}) error { // dst MUST be a pointer to a array type if kind := dst.Kind(); kind != reflect.Ptr { - return errors.Errorf(`dst must be a pointer to a array (%s)`, dst.Type()) + return fmt.Errorf(`dst must be a pointer to a array (%s)`, dst.Type()) } dst = dst.Elem() switch dst.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf(`dst must be a pointer to an array or slice (%s)`, dst.Type()) + return fmt.Errorf(`dst must be a pointer to an array or slice (%s)`, dst.Type()) } var pairs []*Pair @@ -165,7 +164,7 @@ func AsArray(ctx context.Context, s interface{}, v interface{}) error { switch dst.Kind() { case reflect.Array: if len(pairs) < dst.Len() { - return errors.Errorf(`dst array does not have enough space for elements (%d, want %d)`, dst.Len(), len(pairs)) + return fmt.Errorf(`dst array does not have enough space for elements (%d, want %d)`, dst.Len(), len(pairs)) } case reflect.Slice: if dst.IsNil() { @@ -175,7 +174,7 @@ func AsArray(ctx context.Context, s interface{}, v interface{}) error { // dst must be assignable if !dst.CanSet() { - return errors.New(`dst is not writeable`) + return fmt.Errorf(`dst is not writeable`) } elemtyp := dst.Type().Elem() @@ -183,7 +182,7 @@ func AsArray(ctx context.Context, s interface{}, v interface{}) error { rvvalue := reflect.ValueOf(pair.Value) if !rvvalue.Type().AssignableTo(elemtyp) { - return errors.Errorf(`cannot assign key of type %s to map key of type %s`, rvvalue.Type(), elemtyp) + return fmt.Errorf(`cannot assign key of type %s to map key of type %s`, rvvalue.Type(), elemtyp) } dst.Index(pair.Index).Set(rvvalue) diff --git a/go.mod b/go.mod index 7cdb686..48a5f71 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,4 @@ module github.com/lestrrat-go/iter go 1.13 -require ( - github.com/pkg/errors v0.9.1 - github.com/stretchr/testify v1.5.1 -) +require github.com/stretchr/testify v1.5.1 diff --git a/go.sum b/go.sum index 4516e6a..331fa69 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/mapiter/mapiter.go b/mapiter/mapiter.go index 331a978..ec33285 100644 --- a/mapiter/mapiter.go +++ b/mapiter/mapiter.go @@ -2,10 +2,9 @@ package mapiter import ( "context" + "fmt" "reflect" "sync" - - "github.com/pkg/errors" ) // Iterate creates an iterator from arbitrary map types. This is not @@ -17,7 +16,7 @@ func Iterate(ctx context.Context, m interface{}) (Iterator, error) { mrv := reflect.ValueOf(m) if mrv.Kind() != reflect.Map { - return nil, errors.Errorf(`argument must be a map (%s)`, mrv.Type()) + return nil, fmt.Errorf(`argument must be a map (%s)`, mrv.Type()) } ch := make(chan *Pair) @@ -121,7 +120,7 @@ func Walk(ctx context.Context, s Source, v Visitor) error { for i := s.Iterate(ctx); i.Next(ctx); { pair := i.Pair() if err := v.Visit(pair.Key, pair.Value); err != nil { - return errors.Wrapf(err, `failed to visit key %s`, pair.Key) + return fmt.Errorf(`failed to visit key %s: %w`, pair.Key, err) } } return nil @@ -134,13 +133,13 @@ func AsMap(ctx context.Context, s interface{}, v interface{}) error { case reflect.Map: x, err := Iterate(ctx, s) if err != nil { - return errors.Wrap(err, `failed to iterate over map type`) + return fmt.Errorf(`failed to iterate over map type: %w`, err) } iter = x default: ssrc, ok := s.(Source) if !ok { - return errors.Errorf(`cannot iterate over %T: not a mapiter.Source type`, s) + return fmt.Errorf(`cannot iterate over %T: not a mapiter.Source type`, s) } iter = ssrc.Iterate(ctx) } @@ -149,12 +148,12 @@ func AsMap(ctx context.Context, s interface{}, v interface{}) error { // dst MUST be a pointer to a map type if kind := dst.Kind(); kind != reflect.Ptr { - return errors.Errorf(`dst must be a pointer to a map (%s)`, dst.Type()) + return fmt.Errorf(`dst must be a pointer to a map (%s)`, dst.Type()) } dst = dst.Elem() if dst.Kind() != reflect.Map { - return errors.Errorf(`dst must be a pointer to a map (%s)`, dst.Type()) + return fmt.Errorf(`dst must be a pointer to a map (%s)`, dst.Type()) } if dst.IsNil() { @@ -163,7 +162,7 @@ func AsMap(ctx context.Context, s interface{}, v interface{}) error { // dst must be assignable if !dst.CanSet() { - return errors.New(`dst is not writeable`) + return fmt.Errorf(`dst is not writeable`) } keytyp := dst.Type().Key() @@ -176,7 +175,7 @@ func AsMap(ctx context.Context, s interface{}, v interface{}) error { rvvalue := reflect.ValueOf(pair.Value) if !rvkey.Type().AssignableTo(keytyp) { - return errors.Errorf(`cannot assign key of type %s to map key of type %s`, rvkey.Type(), keytyp) + return fmt.Errorf(`cannot assign key of type %s to map key of type %s`, rvkey.Type(), keytyp) } switch rvvalue.Kind() { @@ -185,7 +184,7 @@ func AsMap(ctx context.Context, s interface{}, v interface{}) error { rvvalue = reflect.New(valtyp).Elem() default: if !rvvalue.Type().AssignableTo(valtyp) { - return errors.Errorf(`cannot assign value of type %s to map value of type %s`, rvvalue.Type(), valtyp) + return fmt.Errorf(`cannot assign value of type %s to map value of type %s`, rvvalue.Type(), valtyp) } }