Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address issue 18662 to display accurate error messages. #18663

Merged
merged 4 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ field. You can revert this change by configuring tags for the module and omittin
- Fix panic when assigning a key to a `nil` value in an event. {pull}18143[18143]
- Gives monitoring reporter hosts, if configured, total precedence over corresponding output hosts. {issue}17937[17937] {pull}17991[17991]
- Change `decode_json_fields` processor, to merge parsed json objects with existing objects in the event instead of fully replacing them. {pull}17958[17958]
- 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{}:
alakahakai marked this conversation as resolved.
Show resolved Hide resolved
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
default:
msg := fmt.Sprintf("expected dictionary, found %T", subData)
alakahakai marked this conversation as resolved.
Show resolved Hide resolved
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