From 3bd6a209a45bdc9843c1d1ce2c3fbb4b8d95bf63 Mon Sep 17 00:00:00 2001 From: Jim Date: Wed, 11 Aug 2021 15:24:48 -0400 Subject: [PATCH] prevent panic when hclog_formatter_node is operating on a struct (#1456) --- CHANGELOG.md | 5 +++++ internal/observability/event/hclog_formatter_node.go | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index abdbafae69..dfcdc70936 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ Canonical reference for changes, improvements, and bugfixes for Boundary. ## Next +### Bug Fixes + +* events: Fix panic when using the `hclog-text` event's format. + ([PR](https://github.com/hashicorp/boundary/pull/1456)) + ## 0.5.0 (2021/08/02) ### Deprecations/Changes diff --git a/internal/observability/event/hclog_formatter_node.go b/internal/observability/event/hclog_formatter_node.go index eeccf0cc17..69af2b2acb 100644 --- a/internal/observability/event/hclog_formatter_node.go +++ b/internal/observability/event/hclog_formatter_node.go @@ -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) }