Merge pull request #2487 from skriss/fix-error-logging

don't return an error from log hook if value is not an error type
pull/2500/head
Nolan Brubaker 2020-05-01 16:11:16 -04:00 committed by GitHub
commit 577af5a5b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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",