Skip to content

Commit

Permalink
feat: override exception type by optional error interface (#43)
Browse files Browse the repository at this point in the history
Prefer TypeName as provided by go-errors/errors or a custom implementation,
allowing for specific sentry titles instead of generic container names.
Same stringification (like *errors.errorString) as before for anything else.

Co-authored-by: Mischa Poslawsky <[email protected]>
  • Loading branch information
shiar and shiar authored Oct 25, 2023
1 parent a204565 commit 88b0e28
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion core.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (c *core) addExceptionsFromError(

processedErrors[getTypeOf(err)] = struct{}{}

exception := sentry.Exception{Value: err.Error(), Type: reflect.TypeOf(err).String()}
exception := sentry.Exception{Value: err.Error(), Type: getTypeName(err)}

if !c.cfg.DisableStacktrace {
exception.Stacktrace = sentry.ExtractStacktrace(err)
Expand All @@ -278,6 +278,14 @@ func (c *core) addExceptionsFromError(
return exceptions
}

func getTypeName(err error) string {
switch cast := err.(type) {
case interface{ TypeName() string }:
return cast.TypeName()
}
return reflect.TypeOf(err).String()
}

func (c *core) hub() *sentry.Hub {
if c.cfg.Hub != nil {
return c.cfg.Hub
Expand Down

0 comments on commit 88b0e28

Please sign in to comment.