Skip to content

Commit

Permalink
ErrIllegalTagType prints tag type
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdata committed Jan 16, 2024
1 parent 2352776 commit ab50136
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 10 additions & 4 deletions tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ func (errTooManyTags) Error() string {

var ErrTooManyTags = errTooManyTags{}

type errIllegalTagType struct{}
type errIllegalTagType struct {
tag any
}

func (e errIllegalTagType) Error() string {
return fmt.Sprintf("illegal tag type %T", e.tag)
}

func (errIllegalTagType) Error() string {
return "illegal tag type"
func (errIllegalTagType) Is(other error) bool {
return other == ErrIllegalTagType
}

var ErrIllegalTagType = errIllegalTagType{}
Expand Down Expand Up @@ -82,7 +88,7 @@ func tagExpand(l int, rq *Request, tag interface{}, result []interface{}) ([]int
default:
return append(result, data), nil
}
return result, ErrIllegalTagType
return result, errIllegalTagType{tag: tag}
}

func TagExpand(rq *Request, tag interface{}) ([]interface{}, error) {
Expand Down
6 changes: 5 additions & 1 deletion tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"html/template"
"reflect"
"strings"
"sync/atomic"
"testing"
)
Expand Down Expand Up @@ -80,7 +81,10 @@ func TestTagExpand_IllegalTypesPanic(t *testing.T) {
if !ok {
t.Fail()
}
if e.Error() != ErrIllegalTagType.Error() {
if !errors.Is(e, ErrIllegalTagType) {
t.Fail()
}
if !strings.Contains(e.Error(), fmt.Sprintf("%T", tag)) {
t.Fail()
}
}()
Expand Down

0 comments on commit ab50136

Please sign in to comment.