by stepforward · 7y ago · 0 comments
Should `try` wraps the error and adds something more useful for debugging purpose? (the line number probably?)
That wouldn't work in a deferred function. Perhaps the compiler could make that possible somehow although I suspect that might conflict with the stated goal of improving the efficiency of defer due to "try" encouraging more people to use it.
As a result, I believe juju/errors could then be extended with a new function, to be used like this:
func foobar(...) (..., err error) {
defer errors.Tracify(&err)
...
}
where: package juju/errors
func Tracify(err *error) {
if *err != nil {
*err = TraceFromDefer(*err)
}
}