don't return an error from log hook if value is not an error type

Signed-off-by: Steve Kriss <krisss@vmware.com>
This commit is contained in:
Steve Kriss
2020-04-30 15:22:45 -06:00
parent e148ddad8f
commit 5cc6c12eb4
3 changed files with 5 additions and 2 deletions

View File

@@ -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

View File

@@ -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 {

View File

@@ -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",