From d310f9d16b9c949f089cc9bee37e82e0d06ff2d6 Mon Sep 17 00:00:00 2001 From: Soulou Date: Fri, 7 Apr 2023 00:53:57 +0200 Subject: [PATCH 1/3] Do not use errgo nor pkg/errors for root errors Related to #582 --- errors/errctx.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/errors/errctx.go b/errors/errctx.go index 9d014aa2..e50a5bb9 100644 --- a/errors/errctx.go +++ b/errors/errctx.go @@ -25,30 +25,41 @@ func (err ErrCtx) Unwrap() error { return err.err } -func New(ctx context.Context, message string) error { - return ErrCtx{ctx: ctx, err: errgo.New(message)} +// New wraps errors.New from the pkg/errors library +// +// These errors are usually created outside any function code at the top of +// files, so no context is needed. +func New(message string) error { + return errors.New(message) +} + +func NewWithCtx(ctx context.Context, message string) error { + return ErrCtx{ctx: ctx, err: errors.New(message)} } func Newf(ctx context.Context, format string, args ...interface{}) error { - return ErrCtx{ctx: ctx, err: errgo.Newf(format, args...)} + return ErrCtx{ctx: ctx, err: errors.Errorf(format, args...)} } +func Errorf(ctx context.Context, format string, args ...interface{}) error { + return ErrCtx{ctx: ctx, err: errors.Errorf(format, args...)} +} + +// Notef is wrapping an error with the underneath errgo library func Notef(ctx context.Context, err error, format string, args ...interface{}) error { return ErrCtx{ctx: ctx, err: errgo.Notef(err, format, args...)} } +// Wrap is wrapping an error with the underneath errgo library func Wrap(ctx context.Context, err error, message string) error { return ErrCtx{ctx: ctx, err: errors.Wrap(err, message)} } +// Wrapf is wrapping an error with the underneath errgo library func Wrapf(ctx context.Context, err error, format string, args ...interface{}) error { return ErrCtx{ctx: ctx, err: errors.Wrapf(err, format, args...)} } -func Errorf(ctx context.Context, format string, args ...interface{}) error { - return ErrCtx{ctx: ctx, err: errors.Errorf(format, args...)} -} - // RootCtxOrFallback unwrap all wrapped errors from err to get the deepest context // from ErrCtx errors. If there is no wrapped ErrCtx RootCtxOrFallback returns ctx from parameter. func RootCtxOrFallback(ctx context.Context, err error) context.Context { From 5dce05d33266fc68af932882d8389803d660d08f Mon Sep 17 00:00:00 2001 From: Soulou <329969+Soulou@users.noreply.github.com> Date: Wed, 3 May 2023 11:15:50 +0200 Subject: [PATCH 2/3] Update errors/errctx.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Étienne M. --- errors/errctx.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/errors/errctx.go b/errors/errctx.go index e50a5bb9..82aac93e 100644 --- a/errors/errctx.go +++ b/errors/errctx.go @@ -50,7 +50,7 @@ func Notef(ctx context.Context, err error, format string, args ...interface{}) e return ErrCtx{ctx: ctx, err: errgo.Notef(err, format, args...)} } -// Wrap is wrapping an error with the underneath errgo library +// Wrap is wrapping an error with the underneath errors library func Wrap(ctx context.Context, err error, message string) error { return ErrCtx{ctx: ctx, err: errors.Wrap(err, message)} } From fc37451716ad983d1ad14e778da32e421e5269d2 Mon Sep 17 00:00:00 2001 From: Soulou <329969+Soulou@users.noreply.github.com> Date: Wed, 3 May 2023 11:15:57 +0200 Subject: [PATCH 3/3] Update errors/errctx.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Étienne M. --- errors/errctx.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/errors/errctx.go b/errors/errctx.go index 82aac93e..7901c197 100644 --- a/errors/errctx.go +++ b/errors/errctx.go @@ -55,7 +55,7 @@ func Wrap(ctx context.Context, err error, message string) error { return ErrCtx{ctx: ctx, err: errors.Wrap(err, message)} } -// Wrapf is wrapping an error with the underneath errgo library +// Wrapf is wrapping an error with the underneath errors library func Wrapf(ctx context.Context, err error, format string, args ...interface{}) error { return ErrCtx{ctx: ctx, err: errors.Wrapf(err, format, args...)} }