better error message.

pull/256/head
joeybloggs 9 years ago
parent 5fedd8c08a
commit 2fe87f7a8d
  1. 6
      cache.go
  2. 10
      validator_test.go

@ -21,8 +21,8 @@ const (
)
const (
invalidValidation = "Invalid validation tag on field %s"
undefinedValidation = "Undefined validation function on field %s"
invalidValidation = "Invalid validation tag on field '%s'"
undefinedValidation = "Undefined validation function '%s' on field '%s'"
)
// var (
@ -267,7 +267,7 @@ func (v *Validate) parseFieldTagsRecursive(tag string, fieldName string, alias s
}
if current.fn, ok = v.validations[current.tag]; !ok {
panic(strings.TrimSpace(fmt.Sprintf(undefinedValidation, fieldName)))
panic(strings.TrimSpace(fmt.Sprintf(undefinedValidation, current.tag, fieldName)))
}
if len(orVals) > 1 {

@ -2625,7 +2625,7 @@ func TestBadKeyValidation(t *testing.T) {
validate := New()
PanicMatches(t, func() { validate.Struct(tst) }, "Undefined validation function on field Name")
PanicMatches(t, func() { validate.Struct(tst) }, "Undefined validation function ' ' on field 'Name'")
type Test2 struct {
Name string `validate:"required,,len=2"`
@ -2635,7 +2635,7 @@ func TestBadKeyValidation(t *testing.T) {
Name: "test",
}
PanicMatches(t, func() { validate.Struct(tst2) }, "Invalid validation tag on field Name")
PanicMatches(t, func() { validate.Struct(tst2) }, "Invalid validation tag on field 'Name'")
}
func TestInterfaceErrValidation(t *testing.T) {
@ -5413,8 +5413,8 @@ func TestOrTag(t *testing.T) {
s = "this is right, but a blank or isn't"
PanicMatches(t, func() { validate.Var(s, "rgb||len=13") }, "Invalid validation tag on field")
PanicMatches(t, func() { validate.Var(s, "rgb|rgbaa|len=13") }, "Undefined validation function on field")
PanicMatches(t, func() { validate.Var(s, "rgb||len=13") }, "Invalid validation tag on field ''")
PanicMatches(t, func() { validate.Var(s, "rgb|rgbaa|len=13") }, "Undefined validation function 'rgbaa' on field ''")
}
func TestHsla(t *testing.T) {
@ -6116,7 +6116,7 @@ func TestInvalidValidatorFunction(t *testing.T) {
Test: "1",
}
PanicMatches(t, func() { validate.Var(s.Test, "zzxxBadFunction") }, "Undefined validation function on field")
PanicMatches(t, func() { validate.Var(s.Test, "zzxxBadFunction") }, "Undefined validation function 'zzxxBadFunction' on field ''")
}
func TestCustomFieldName(t *testing.T) {

Loading…
Cancel
Save