Skip to content

Commit

Permalink
Fix #42 panic occurs if zero stack frames (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
evalphobia committed Apr 14, 2017
1 parent 01c8211 commit 7c1b7fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ func (hook *SentryHook) Fire(entry *logrus.Entry) error {
packet.Culprit = err.Error()
} else {
currentStacktrace := raven.NewStacktrace(stConfig.Skip, stConfig.Context, stConfig.InAppPrefixes)
packet.Interfaces = append(packet.Interfaces, currentStacktrace)
if currentStacktrace != nil {
packet.Interfaces = append(packet.Interfaces, currentStacktrace)
}
}
} else {
// set the culprit even when the stack trace is disabled, as long as we have an error
Expand Down
10 changes: 10 additions & 0 deletions sentry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,16 @@ func TestSentryStacktrace(t *testing.T) {
if !strings.HasSuffix(frames[0].Filename, expectedPkgErrorsStackTraceFilename) {
t.Error("Stacktrace should be taken from err if it implements the pkgErrorStackTracer interface")
}

// zero stack frames
defer func() {
if err := recover(); err != nil {
t.Error("Zero stack frames should not cause panic")
}
}()
hook.StacktraceConfiguration.Skip = 1000
logger.Error(message)
<-pch // check panic
})
}

Expand Down

0 comments on commit 7c1b7fa

Please sign in to comment.