Skip to content

Commit

Permalink
fix: Report usage error including stack trace
Browse files Browse the repository at this point in the history
Prior to this, calling CaptureException, Recover or RecoverWithContext
with a nil error would send a message event to Sentry without a stack
trace.

Looking at the Sentry issues list, and issue detail, all you see is
"Called CaptureException with nil value" without a clue of what caused
it.

This commit turns that message into a sentry.usageError with a stack
trace, making it easier to understand what is wrong and fix user code.
  • Loading branch information
rhcarvalho committed Apr 3, 2020
1 parent 406f4d6 commit 0186c1a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ import (
"time"
)

// usageError is used to report to Sentry an SDK usage error.
//
// It is not exported because it is never returned by any function or method in
// the exported API.
type usageError struct {
error
}

// Logger is an instance of log.Logger that is use to provide debug information about running Sentry Client
// can be enabled by either using `Logger.SetOutput` directly or with `Debug` client option
var Logger = log.New(ioutil.Discard, "[Sentry] ", log.LstdFlags) //nolint: gochecknoglobals
Expand Down Expand Up @@ -299,10 +307,7 @@ func (client *Client) eventFromMessage(message string, level Level) *Event {

func (client *Client) eventFromException(exception error, level Level) *Event {
if exception == nil {
event := NewEvent()
event.Level = level
event.Message = fmt.Sprintf("Called %s with nil value", callerFunctionName())
return event
exception = usageError{fmt.Errorf("%s called with nil error", callerFunctionName())}
}

stacktrace := ExtractStacktrace(exception)
Expand Down

0 comments on commit 0186c1a

Please sign in to comment.