Stdlib errors
package extension. go1.13
errors.Is
and errors.As
are the same functions as in stdlib (not even copies).
// as usual
err = errors.New("msg")
// do not capture caller info
err = errors.NewNoLoc("msg")
// fmt.Sprintf like
err = errors.New("message %v", "args")
// one Frame higher
err = errors.NewDepth(1, "msg")
// the same result as previous
pc := loc.Caller(1)
err = errors.NewLoc(pc, "msg")
// Wrap error
err = errors.Wrap(err, "msg %v", "args")
// all the same function types are available
err = errors.WrapNoLoc(err, "msg")
err = errors.WrapDepth(err, 1, "msg %v", "args")
err = errors.WrapLoc(err, pc, "msg %v", "args")
Caller frame can be added to error so later you can get to know where error was generated. It's added by default and captures instruction calling errors.(Wrap|New)*
.
Caller is moved to a separate module tlog.app/go/loc.
pc := loc.Caller(1)
pc = loc.FuncEntry(1)