Skip to content

Commit

Permalink
Improve the quality of tag parsing errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
jchv committed Jun 17, 2017
1 parent 7445de6 commit cef7084
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestParseTag(t *testing.T) {
opts, err := parseTag(test.input)
assert.Equal(t, test.opts, opts)
if err != nil {
assert.Equal(t, test.errstr, err.Error())
assert.Contains(t, err.Error(), test.errstr)
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions typestr.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package restruct

import (
"errors"
"fmt"
"go/ast"
"go/parser"
"go/token"
"reflect"
"strconv"

"github.com/pkg/errors"
)

// typeMap maps identifiers to reflect.Types.
Expand Down Expand Up @@ -99,7 +100,7 @@ func typeOfExpr(expr ast.Expr) (reflect.Type, error) {
func parseType(typ string) (reflect.Type, error) {
expr, err := parser.ParseExpr(typ)
if err != nil {
return nil, errors.New("parsing error")
return nil, errors.Wrap(err, "parsing error")
}

return typeOfExpr(expr)
Expand Down
2 changes: 1 addition & 1 deletion typestr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestParseType(t *testing.T) {
assert.Equal(t, test.typ.String(), typ.String())
}
if err != nil {
assert.Equal(t, test.errstr, err.Error())
assert.Contains(t, err.Error(), test.errstr)
}
}
}
Expand Down

0 comments on commit cef7084

Please sign in to comment.