Márk Sági-Kazár
2019-07-22
Emperror became a huge dependency
Solution: Split up the module into smaller ones
emperror.dev/emperror
Unwrap
As
Is
Unwrap
type myError struct { err error }
func (e myError) Error() string { return e.err.Error() }
func (e myError) Unwrap() error { return e.err }
func (e myError) Cause() error { return e.err }
err1 := errors.New("error")
err2 := &myError{err1}
err3 := &myError{err2}
err := errors.Unwrap(err3) // == err2
// BUT
err := pkgErrors.Cause(err3) // == err1 (!!!)
As
err := pkgErrors.New("error")
var stackTracer interface{ StackTrace() pkgErrors.StackTrace }
if errors.As(err, &stackTracer) {
st := stackTracer.StackTrace()
}
“Assert errors for behaviour, not type” - Dave Cheney
Is
Partial incompatibility with github.com/pkg/errors
Only from Go 1.13
No stack trace
Solution: New error library
emperror.dev/errors
Drop-in replacement for errors
and github.com/pkg/errors
Merged parts of Emperror into the new library
Tested with replaced library test suites
Old | New |
---|---|
github.com/goph/emperror |
emperror.dev/emperror |
github.com/goph/emperror/handler/*handler |
emperror.dev/handler/* |
(no previous module) | emperror.dev/errors |
Old | New |
---|---|
emperror.Wrap |
errors.WrapIf |
emperror.Wrapf |
emperror.WrapIff |
emperror.With |
errors.WithDetails |
emperror.WrapWith |
errors.WrapIfWithDetails |
emperror.Context |
errors.GetDetails |
emperror.NewMultiErrorBuilder |
errors.Combine |
emperror.ForEachCause |
errors.UnwrapEach |
emperror.HandlerWith |
emperror.WithDetails |
emperror.HandlerWithPrefix |
(no replacement yet) |
NewWithDetails
NewPlain
WithStackDepth
/ WithStackDepthIf
https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully
https://8thlight.com/blog/kyle-krull/2018/08/13/exploring-error-handling-patterns-in-go.html
https://go.googlesource.com/proposal/+/master/design/go2draft-error-handling-overview.md
https://go.googlesource.com/proposal/+/master/design/go2draft-error-values-overview.md