Skip to content

Commit

Permalink
Remove pkg/errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lestrrat committed Mar 29, 2022
1 parent 370527f commit 6d2eafe
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
11 changes: 5 additions & 6 deletions blackmagic.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package blackmagic

import (
"fmt"
"reflect"

"github.com/pkg/errors"
)

// AssignIfCompatible is a convenience function to safely
Expand All @@ -23,12 +22,12 @@ func AssignIfCompatible(dst, src interface{}) error {
case reflect.Slice:
isSlice = true
default:
return errors.Errorf("argument t to AssignIfCompatible must be a pointer or a slice: %T", src)
return fmt.Errorf("argument t to AssignIfCompatible must be a pointer or a slice: %T", src)
}

rv := reflect.ValueOf(dst)
if rv.Kind() != reflect.Ptr {
return errors.Errorf(`argument to AssignIfCompatible() must be a pointer: %T`, dst)
return fmt.Errorf(`argument to AssignIfCompatible() must be a pointer: %T`, dst)
}

actualDst := rv.Elem()
Expand All @@ -43,11 +42,11 @@ func AssignIfCompatible(dst, src interface{}) error {
}
}
if !result.Type().AssignableTo(actualDst.Type()) {
return errors.Errorf(`argument to AssignIfCompatible() must be compatible with %T (was %T)`, orv.Interface(), dst)
return fmt.Errorf(`argument to AssignIfCompatible() must be compatible with %T (was %T)`, orv.Interface(), dst)
}

if !actualDst.CanSet() {
return errors.Errorf(`argument to AssignIfCompatible() must be settable`)
return fmt.Errorf(`argument to AssignIfCompatible() must be settable`)
}
actualDst.Set(result)

Expand Down
9 changes: 9 additions & 0 deletions blackmagic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ func TestAssignment(t *testing.T) {
return &v
},
},
{
Name: `lestrrat-go/jwx#389`,
Error: true,
Value:
Destination: func() interface{} {
var s struct{}
return &s
},
},
}

for _, tc := range testcases {
Expand Down
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ module github.com/lestrrat-go/blackmagic

go 1.16

require (
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.0
)
require github.com/stretchr/testify v1.7.1
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
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 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
Expand Down

0 comments on commit 6d2eafe

Please sign in to comment.