go-playground / validator

:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
MIT License
16.83k stars 1.32k forks source link

When using validate tag "gte=0" does not return ValidationError, but strconv.ParseInt error #1020

Open andresuchitra opened 2 years ago

andresuchitra commented 2 years ago

Package version eg. v9, v10:

v10

Issue, Question or Enhancement:

When using validate tag "gte=0" or "numeric", calling validate.Struct() does not return ValidationError, but strconv.ParseInt error.

strconv.ParseInt: parsing \"-1a\": invalid syntax

Code sample, to showcase or reproduce:

Struct that I used:

type Param struct {
 Page int `json:"page" validate:"numeric,gte=0"`
 Limit int `json:"limit" validate:"numeric,gte=0"`
}

param := Param{
 Page: "aa",
 Limit: "bb",
}

if err := validate.Struct(param); err != nil {
   // err will be strconv error type, not ValidationErrors
}
andresuchitra commented 2 years ago

I raised this as issue, because apparently need to report which fields causing the error. In current behavior, we only received strconv.ErrSyntax after calling Struct() function, thus we can't know the problematic field(s)

vuon9 commented 1 year ago

I'm trying to understand the problem. How can you even use int type but with string value? Is that something wrong with your example?