From 5cc6c12eb4179ff1f6046ac8493372cd79032373 Mon Sep 17 00:00:00 2001 From: Steve Kriss Date: Thu, 30 Apr 2020 15:22:45 -0600 Subject: [PATCH] don't return an error from log hook if value is not an error type Signed-off-by: Steve Kriss --- changelogs/unreleased/2487-skriss | 1 + pkg/util/logging/error_location_hook.go | 4 +++- pkg/util/logging/error_location_hook_test.go | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/2487-skriss diff --git a/changelogs/unreleased/2487-skriss b/changelogs/unreleased/2487-skriss new file mode 100644 index 000000000..c551cfcaa --- /dev/null +++ b/changelogs/unreleased/2487-skriss @@ -0,0 +1 @@ +bug fix: in error location logging hook, if the item logged under the `error` key doesn't implement the `error` interface, don't return an error since this is a valid scenario diff --git a/pkg/util/logging/error_location_hook.go b/pkg/util/logging/error_location_hook.go index 20e2d11da..5246a8318 100644 --- a/pkg/util/logging/error_location_hook.go +++ b/pkg/util/logging/error_location_hook.go @@ -60,7 +60,9 @@ func (h *ErrorLocationHook) Fire(entry *logrus.Entry) error { err, ok := errObj.(error) if !ok { - return errors.New("object logged as error does not satisfy error interface") + // if the value isn't an error type, skip trying to get location info, + // and just let it be logged as whatever it was + return nil } if errorLocationer, ok := err.(errorLocationer); ok { diff --git a/pkg/util/logging/error_location_hook_test.go b/pkg/util/logging/error_location_hook_test.go index e7ab47cab..b45f0ed12 100644 --- a/pkg/util/logging/error_location_hook_test.go +++ b/pkg/util/logging/error_location_hook_test.go @@ -47,7 +47,7 @@ func TestFire(t *testing.T) { name: "non-error logged in error field", preEntryFields: map[string]interface{}{logrus.ErrorKey: "not an error"}, expectedEntryFields: map[string]interface{}{logrus.ErrorKey: "not an error"}, - expectedErr: true, + expectedErr: false, }, { name: "pkg/errors error",