honeybadger-io / honeybadger-go

Send Go (golang) panics and errors to Honeybadger.
https://www.honeybadger.io/
MIT License
34 stars 15 forks source link

Make newError function public #6

Closed kostyantyn closed 8 years ago

kostyantyn commented 8 years ago

When you don't send an error to honeybadger straightaway, you lose the trace. Having a public NewError method, you can wrap your error to get a proper trace.

For instance:

func one() {
    if err := two(); err != nil {
        honeybadger.Notify(err)
    }
}

func two() error {
    return three()
}

func three() error {
    return errors.New("Error")
}

In this case we won't see that error happened in function three.

However, having an access to NewError we can keep the trace:

func three() error {
    err := errors.New("Error")
    return honeybadger.NewError(err, 0)
}
kostyantyn commented 8 years ago

Might be it's even better to remove second parameter from the public NewError function.

For instance:

func NewError(thing interface{}) Error {
    return newError(thing, 2)
}
joshuap commented 8 years ago

+1. I think removing the second parameter would be good as long as there isn't a case where you would need to specify a different offset for the stack trace; we use the offset internally to remove honeybadger lines which aren't actually part of the trace. Do you want to update it?

kostyantyn commented 8 years ago

updated PR. Please, review it again

joshuap commented 8 years ago

Looks good, thanks!