Skip to content

Commit

Permalink
Handle error when invalid data is supplied for diving
Browse files Browse the repository at this point in the history
  • Loading branch information
zytell3301 committed Apr 18, 2021
1 parent b20f973 commit 870c998
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion validator_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ func (v Validate) ValidateMapCtx(ctx context.Context, data map[string]interface{
if len(err) > 0 {
errs[field] = err
}
} else if reflect.ValueOf(rule).Kind() == reflect.Map {
errs[field] = errors.New("The field: '" + field + "' is not a map to dive")
} else {
err := v.VarCtx(ctx, data[field], rule.(string))
if err != nil {
Expand All @@ -165,7 +167,7 @@ func (v Validate) ValidateMapCtx(ctx context.Context, data map[string]interface{

// ValidateMap validates map data form a map of tags
func (v *Validate) ValidateMap(data map[string]interface{}, rules map[string]interface{}) map[string]interface{} {
return v.ValidateMapCtx(context.Background(),data,rules)
return v.ValidateMapCtx(context.Background(), data, rules)
}

// RegisterTagNameFunc registers a function to get alternate names for StructFields.
Expand Down

0 comments on commit 870c998

Please sign in to comment.