evalphobia / logrus_sentry

sentry hook for logrus
MIT License
194 stars 78 forks source link

NPE introduced by v0.4.5 #64

Open sysradium opened 6 years ago

sysradium commented 6 years ago

In here: https://github.com/evalphobia/logrus_sentry/commit/57846a82817615f185b10cc40de8dc60c1ca5ae1#diff-0b771ec7e8ca759d819dc583bbdc795aR212

We are relying on a fact, that the stacktrace is not nil, however here:

https://github.com/evalphobia/logrus_sentry/commit/57846a82817615f185b10cc40de8dc60c1ca5ae1#diff-0b771ec7e8ca759d819dc583bbdc795aR204

We can still get nil. And sometimes raven.NewStacktrace(...) returns nil, causing all of that panic:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x985fc6]

goroutine 984 [running]:
github.com/.../vendor/github.com/getsentry/raven-go.(*Stacktrace).Culprit(0x0, 0x0, 0x0)
        /go/src/github.com/.../vendor/github.com/getsentry/raven-go/stacktrace.go:29 +0x26
github.com/.../vendor/github.com/evalphobia/logrus_sentry.(*SentryHook).Fire(0xc420129760, 0xc4214007d0, 0x0, 0x0)

So probably a nil check has to be added, like:

if stConfig.SwitchExceptionTypeAndMessage {
    exc.Type, exc.Value = exc.Value, exc.Type
    packet.Interfaces = append(packet.Interfaces, currentStacktrace)
        if currentStacktrace != nil {
          packet.Culprit = exc.Type + ": " + currentStacktrace.Culprit()
        }
} else {