Skip to content

Commit d8ab995

Browse files
committed
add support with unwrap interface on go1.13 and xerrors
1 parent ff59870 commit d8ab995

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

errors.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ type withStack struct {
186186
}
187187

188188
func (w *withStack) Cause() error { return w.error }
189+
func (w *withStack) Unwrap() error { return w.error }
189190

190191
func (w *withStack) Format(s fmt.State, verb rune) {
191192
switch verb {
@@ -298,6 +299,8 @@ type withMessage struct {
298299

299300
func (w *withMessage) Error() string { return w.msg + ": " + w.cause.Error() }
300301
func (w *withMessage) Cause() error { return w.cause }
302+
func (w *withMessage) Unwrap() error { return w.cause }
303+
301304

302305
func (w *withMessage) Format(s fmt.State, verb rune) {
303306
switch verb {
@@ -331,7 +334,7 @@ func Cause(err error) error {
331334

332335
for err != nil {
333336
var c causer
334-
if !errors.As(err, &c) {
337+
if !As(err, &c) {
335338
break
336339
}
337340
err = c.Cause()

xerrors.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ type withStack struct {
187187
}
188188

189189
func (w *withStack) Cause() error { return w.error }
190+
func (w *withStack) Unwrap() error { return w.error }
190191

191192
func (w *withStack) Format(s fmt.State, verb rune) {
192193
switch verb {
@@ -291,6 +292,7 @@ type withMessage struct {
291292

292293
func (w *withMessage) Error() string { return w.msg + ": " + w.cause.Error() }
293294
func (w *withMessage) Cause() error { return w.cause }
295+
func (w *withMessage) Unwrap() error { return w.cause }
294296

295297
func (w *withMessage) Format(s fmt.State, verb rune) {
296298
switch verb {

0 commit comments

Comments
 (0)