Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dead panic in Entry.Panic #1212

Merged
merged 1 commit into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down