prevent panic when hclog_formatter_node is operating on a struct (#1456)

This commit is contained in:
Jim authored and GitHub committed 2021-08-11 15:24:48 -04:00
1 parent 624bdbf0c2
commit 3bd6a209a4
2 files changed
+11 -1

No files matched your search

@@ -118,8 +118,10 @@ func (f *hclogFormatterFilter) Process(ctx context.Context, e *eventlogger.Event
continue
}
if !f.jsonFormat && v != nil {
var underlyingPtr bool
valueKind := reflect.TypeOf(v).Kind()
if valueKind == reflect.Ptr {
underlyingPtr = true
valueKind = reflect.TypeOf(v).Elem().Kind()
}
switch {
@@ -128,7 +130,10 @@ func (f *hclogFormatterFilter) Process(ctx context.Context, e *eventlogger.Event
args = append(args, k+":"+sk, sv)
}
continue
case valueKind == reflect.Struct && v != nil && !reflect.ValueOf(v).IsNil():
case valueKind == reflect.Struct:
if underlyingPtr && (v == nil || reflect.ValueOf(v).IsNil()) {
continue
}
for sk, sv := range structs.Map(v) {
args = append(args, k+":"+sk, sv)
}