-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create an error embedding a context for future error handling
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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...)} | ||
} |