Skip to content

Commit

Permalink
Create an error embedding a context for future error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Soulou committed Jan 4, 2018
1 parent 1246c68 commit 124f719
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions errors/errctx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package errors

import (
"context"

"gopkg.in/errgo.v1"

"github.com/pkg/errors"
)

type ErrCtx struct {
ctx context.Context
err error
}

func (err ErrCtx) Error() string {
return err.err.Error()
}

func (err ErrCtx) Ctx() context.Context {
return err.ctx
}

func Notef(ctx context.Context, err error, format string, args ...interface{}) error {
return ErrCtx{ctx: ctx, err: errgo.Notef(err, format, args...)}
}

func Wrapf(ctx context.Context, err error, format string, args ...interface{}) error {
return ErrCtx{ctx: ctx, err: errors.Wrapf(err, format, args...)}
}

0 comments on commit 124f719

Please sign in to comment.