Skip to content

Commit

Permalink
👔 up: update the error string format on only one error
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jan 21, 2024
1 parent ab0111b commit a567209
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ func (es Errors) String() string {
for field, fe := range es {
// only one error, return simple format: "field: message"
if ln == 1 && len(fe) == 1 {
for _, msg := range fe {
return fmt.Sprintf("%s: %s", field, msg)
for vName, msg := range fe {
return fmt.Sprintf("%s: %s", vName, msg)
}
}

Expand Down
2 changes: 1 addition & 1 deletion messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestErrorsBasic(t *testing.T) {
assert.Len(t, es, 1)
assert.Equal(t, "error msg0", es.One())
assert.Equal(t, "error msg0", es.FieldOne("field"))
assert.Equal(t, "field: error msg0", es.String())
assert.Equal(t, "required: error msg0", es.String())

es.Add("field2", "min", "error msg2")
assert.Contains(t, fmt.Sprintf("%v", es.All()), "field:map[required:error msg0]")
Expand Down

0 comments on commit a567209

Please sign in to comment.