diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 493e712c4e6..91c108dc815 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -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* diff --git a/libbeat/common/schema/mapstriface/mapstriface.go b/libbeat/common/schema/mapstriface/mapstriface.go index d08631f78c4..ea01d266649 100644 --- a/libbeat/common/schema/mapstriface/mapstriface.go +++ b/libbeat/common/schema/mapstriface/mapstriface.go @@ -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 {