Skip to content

Commit

Permalink
Use owl.ErrUnsupportedType to allow detecting type of error
Browse files Browse the repository at this point in the history
  • Loading branch information
alecsammon committed Jan 10, 2024
1 parent 5d958eb commit fc07fa7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func TestCore_Decode_ErrUnsupporetedType(t *testing.T) {
co, err := New(Cursor{})
assert.NoError(t, err)
got, err := co.Decode(r)
assert.ErrorIs(t, err, internal.ErrUnsupportedType)
assert.ErrorIs(t, err, owl.ErrUnsupportedType)
assert.ErrorContains(t, err, "ObjectID")
assert.Nil(t, got)
}()
Expand All @@ -244,7 +244,7 @@ func TestCore_Decode_ErrUnsupporetedType(t *testing.T) {
co, err := New(Payload{})
assert.NoError(t, err)
got, err := co.Decode(r)
assert.ErrorIs(t, err, internal.ErrUnsupportedType)
assert.ErrorIs(t, err, owl.ErrUnsupportedType)
assert.ErrorContains(t, err, "ObjectID")
assert.Nil(t, got)
}()
Expand Down
4 changes: 2 additions & 2 deletions core/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"net/url"
"testing"

"github.com/ggicci/httpin/internal"
"github.com/stretchr/testify/assert"
"github.com/ggicci/owl"
)

func TestDirectiveQuery_Decode(t *testing.T) {
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestDirectiveQuery_NewRequest_ErrUnsupportedType(t *testing.T) {
co, err := New(SearchQuery{})
assert.NoError(t, err)
_, err = co.NewRequest("GET", "/pets", &SearchQuery{})
assert.ErrorIs(t, err, internal.ErrUnsupportedType)
assert.ErrorIs(t, err, owl.ErrUnsupportedType)
}

// See hybridcoder_test.go for more details.
Expand Down
3 changes: 2 additions & 1 deletion core/stringable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/ggicci/httpin/internal"
"github.com/ggicci/httpin/patch"
"github.com/stretchr/testify/assert"
"github.com/ggicci/owl"
)

type Point2D struct {
Expand Down Expand Up @@ -234,7 +235,7 @@ func testAssignString(t *testing.T, rv reflect.Value, value string) {

func testNewStringableErrUnsupported(t *testing.T, rv reflect.Value) {
s, err := NewStringable(rv, nil)
assert.ErrorIs(t, err, internal.ErrUnsupportedType)
assert.ErrorIs(t, err, owl.ErrUnsupportedType)
assert.Nil(t, s)
}

Expand Down
6 changes: 3 additions & 3 deletions internal/stringable.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"strconv"
"strings"
"time"
"github.com/ggicci/owl"
)

var (
ErrUnsupportedType = errors.New("unsupported type")
ErrTypeMismatch = errors.New("type mismatch")
ErrTypeMismatch = errors.New("type mismatch")

builtinStringableAdaptors = make(map[reflect.Type]AnyStringableAdaptor)
)
Expand Down Expand Up @@ -380,5 +380,5 @@ func (bs *ByteSlice) FromString(s string) error {
}

func UnsupportedType(rt reflect.Type) error {
return fmt.Errorf("%w: %v", ErrUnsupportedType, rt)
return fmt.Errorf("%w: %v", owl.ErrUnsupportedType, rt)
}
3 changes: 2 additions & 1 deletion internal/stringable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/ggicci/owl"
)

func TestNewStringable_string(t *testing.T) {
Expand Down Expand Up @@ -156,7 +157,7 @@ func TestNewStringable_ErrUnsupportedType(t *testing.T) {
})
rvStructPointer := reflect.ValueOf(&s)
sv, err := NewStringable(rvStructPointer)
assert.ErrorIs(t, err, ErrUnsupportedType)
assert.ErrorIs(t, err, owl.ErrUnsupportedType)
assert.Nil(t, sv)
}

Expand Down

0 comments on commit fc07fa7

Please sign in to comment.