From 02fcb160055b97acc1381d9d88cb36e74ce2a535 Mon Sep 17 00:00:00 2001 From: Alec Benzer Date: Tue, 15 Dec 2020 18:25:34 -0500 Subject: [PATCH] Remove dead panic in Entry.Panic [Entry.log itself panics][0] when the log level is set to PanicLevel, (and PanicLevel is always eneabled) so this second panic will never be reached. [0]: https://github.com/sirupsen/logrus/blob/8ae478eb8a850a54ea4915a2b572f377de1f9c7e/entry.go#L253 --- entry.go | 1 - entry_test.go | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/entry.go b/entry.go index 2e87f5f3f..1e32a64f7 100644 --- a/entry.go +++ b/entry.go @@ -317,7 +317,6 @@ func (entry *Entry) Fatal(args ...interface{}) { func (entry *Entry) Panic(args ...interface{}) { entry.Log(PanicLevel, args...) - panic(fmt.Sprint(args...)) } // Entry Printf family functions diff --git a/entry_test.go b/entry_test.go index b98e14ad6..df687adee 100644 --- a/entry_test.go +++ b/entry_test.go @@ -167,6 +167,28 @@ func TestEntryPanicf(t *testing.T) { entry.WithField("err", errBoom).Panicf("kaboom %v", true) } +func TestEntryPanic(t *testing.T) { + errBoom := fmt.Errorf("boom again") + + defer func() { + p := recover() + assert.NotNil(t, p) + + switch pVal := p.(type) { + case *Entry: + assert.Equal(t, "kaboom", pVal.Message) + assert.Equal(t, errBoom, pVal.Data["err"]) + default: + t.Fatalf("want type *Entry, got %T: %#v", pVal, pVal) + } + }() + + logger := New() + logger.Out = &bytes.Buffer{} + entry := NewEntry(logger) + entry.WithField("err", errBoom).Panic("kaboom") +} + const ( badMessage = "this is going to panic" panicMessage = "this is broken"