Package errors is the same as github.com/pkg/errors. However, it makes one additional guarantee:
- All errors returned by this package are guaranteed to have a stack trace.
More precisely, all returned errors implement the ErrorWithStackTrace interface:
type ErrorWithStackTrace interface{
error
StackTrace() string
}This allows you to leverage the type system to ensure that all of the errors that you return include a stack trace:
func Foo() ErrorWithStackTraceThis package tries to be a drop-in replacement for github.com/pkg/error. However, there are known caveats:
-
Errors returned by this package do not implement the same StackTracer interface as github.com/pkg/errors.
-
Instances of similar code will no longer compile:
err := errors.New("foo") // returns errors.ErrorWithStackTrace
c, err := net.Listen("...") // returns regular error, won't compileNote that WithMessage also behaves a bit differently as it will add a stack strace to the supplied error if there is not already one.