mirror of https://github.com/gin-gonic/gin.git
bugfix: SliceValidationError has two elements, but the first one is nil
This commit is contained in:
parent
d4a64265f2
commit
a475c6ec7c
|
@ -28,15 +28,12 @@ func (err SliceValidationError) Error() string {
|
||||||
return ""
|
return ""
|
||||||
default:
|
default:
|
||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
if err[0] != nil {
|
for i := 0; i < n; i++ {
|
||||||
fmt.Fprintf(&b, "[%d]: %s", 0, err[0].Error())
|
if err[i] != nil {
|
||||||
}
|
if b.Len() > 0 {
|
||||||
if n > 1 {
|
|
||||||
for i := 1; i < n; i++ {
|
|
||||||
if err[i] != nil {
|
|
||||||
b.WriteString("\n")
|
b.WriteString("\n")
|
||||||
fmt.Fprintf(&b, "[%d]: %s", i, err[i].Error())
|
|
||||||
}
|
}
|
||||||
|
fmt.Fprintf(&b, "[%d]: %s", i, err[i].Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return b.String()
|
return b.String()
|
||||||
|
|
|
@ -25,6 +25,13 @@ func TestSliceValidationError(t *testing.T) {
|
||||||
},
|
},
|
||||||
"[0]: first error\n[1]: second error",
|
"[0]: first error\n[1]: second error",
|
||||||
},
|
},
|
||||||
|
{"has two elements, but the first one is nil",
|
||||||
|
SliceValidationError{
|
||||||
|
nil,
|
||||||
|
errors.New("first error at second place"),
|
||||||
|
},
|
||||||
|
"[1]: first error at second place",
|
||||||
|
},
|
||||||
{"has many elements",
|
{"has many elements",
|
||||||
SliceValidationError{
|
SliceValidationError{
|
||||||
errors.New("first error"),
|
errors.New("first error"),
|
||||||
|
|
Loading…
Reference in New Issue