Skip to content

Commit

Permalink
Address issue 18662 to display accurate error messages. (#18663)
Browse files Browse the repository at this point in the history
* Address issue 18662 to display accurate error messages.

* Update CHANGELOG.next.asciidoc

* Add common.MapStr to check and perform type assertion for subData.
  • Loading branch information
Lei Qiu authored May 26, 2020
1 parent dc7ba20 commit bfe773e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ field. You can revert this change by configuring tags for the module and omittin
- Change `decode_json_fields` processor, to merge parsed json objects with existing objects in the event instead of fully replacing them. {pull}17958[17958]
- [Autodiscover] Check if runner is already running before starting again. {pull}18564[18564]
- Fix `keystore add` hanging under Windows. {issue}18649[18649] {pull}18654[18654]
- Fix an issue where error messages are not accurate in mapstriface. {issue}18662[18662] {pull}18663[18663]

*Auditbeat*

Expand Down
24 changes: 12 additions & 12 deletions libbeat/common/schema/mapstriface/mapstriface.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,23 @@ func (convMap ConvMap) Map(key string, event common.MapStr, data map[string]inte
err.Required = convMap.Required
return multierror.Errors{err}
}
subData, ok := d.(map[string]interface{})
if !ok {
switch subData := d.(type) {
case map[string]interface{}, common.MapStr:
subEvent := common.MapStr{}
_, errors := convMap.Schema.ApplyTo(subEvent, subData.(map[string]interface{}))
for _, err := range errors {
if err, ok := err.(schema.KeyError); ok {
err.SetKey(convMap.Key + "." + err.Key())
}
}
event[key] = subEvent
return errors
default:
msg := fmt.Sprintf("expected dictionary, found %T", subData)
err := schema.NewWrongFormatError(convMap.Key, msg)
logp.Err(err.Error())
return multierror.Errors{err}
}

subEvent := common.MapStr{}
_, errors := convMap.Schema.ApplyTo(subEvent, subData)
for _, err := range errors {
if err, ok := err.(schema.KeyError); ok {
err.SetKey(convMap.Key + "." + err.Key())
}
}
event[key] = subEvent
return errors
}

func (convMap ConvMap) HasKey(key string) bool {
Expand Down

0 comments on commit bfe773e

Please sign in to comment.