-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from aserto-dev/wrapped_error
add WrappedError and logger extraction from ctx
- Loading branch information
Showing
4 changed files
with
226 additions
and
5 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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
/cover.out | ||
/tenant.db | ||
/.ext | ||
/.ext | ||
|
||
# https://github.com/golang/go/issues/53502 | ||
# go.work.sum is machine specific and should not be checked in | ||
# go.work.sum | ||
|
||
.DS_Store |
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,41 @@ | ||
package errors | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
// ContextError represents a standard error | ||
// that can also encapsulate a context. | ||
type ContextError struct { | ||
Err error | ||
Ctx context.Context | ||
} | ||
|
||
func WithContext(err error, ctx context.Context) *ContextError { | ||
return &ContextError{ | ||
Err: err, | ||
Ctx: ctx, | ||
} | ||
} | ||
|
||
func WrapContext(err error, ctx context.Context, message string) *ContextError { | ||
return WithContext(errors.Wrap(err, message), ctx) | ||
} | ||
|
||
func WrapfContext(err error, ctx context.Context, format string, args ...interface{}) *ContextError { | ||
return WithContext(errors.Wrapf(err, format, args...), ctx) | ||
} | ||
|
||
func (ce *ContextError) Error() string { | ||
return ce.Err.Error() | ||
} | ||
|
||
func (ce *ContextError) Cause() error { | ||
return errors.Cause(ce.Unwrap()) | ||
} | ||
|
||
func (ce *ContextError) Unwrap() error { | ||
return ce.Err | ||
} |
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
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