airbrake / gobrake

Airbrake notifier for Golang
https://docs.airbrake.io/docs/platforms/go-lang
MIT License
104 stars 42 forks source link

Make *Notifier.Notify return first argument (error message) #210

Closed vendion closed 3 years ago

vendion commented 3 years ago

It would be nice if *Notifier.Notify also returns what get passed in as the first argument.

This would allow for a bit of streamlining something like the following

log.Error(airBrake.Notify(errors.New(`something went wrong`), nil))
scottsbaldwin commented 3 years ago

Thanks for the suggestion @vendion. The Notify func is intentionally not returning anything since it is intended to be used as an async function.

The Notifier struct ultimately wraps the provided error as a Notice. If Notifier.Notify was refactored to return something, it would make more sense for us to return a Notice rather than the first arg provided to the Notify func. However, that could be achieved using the following:

notice := airbrake.Notice(errors.New(`something went wrong`), nil, 1)
log.Error(notice)
airbrake.SendNoticeAsync(notice) 

It's not a one-liner, but it's possible.