bump dependencies

This commit is contained in:
Jesse Duffield 2021-06-15 08:12:38 +10:00
parent ce7cbe58a0
commit 3dd88d6138
32 changed files with 396 additions and 115 deletions

View file

@ -65,5 +65,16 @@ everyone can benefit.
This package is licensed under the MIT license, see LICENSE.MIT for details.
## Changelog
* v1.1.0 updated to use go1.13's standard-library errors.Is method instead of == in errors.Is
* v1.1.0 updated to use go1.13's standard-library errors.Is method instead of == in errors.Is
* v1.2.0 added `errors.As` from the standard library.
* v1.3.0 *BREAKING* updated error methods to return `error` instead of `*Error`.
> Code that needs access to the underlying `*Error` can use the new errors.AsError(e)
> ```
> // before
> errors.New(err).ErrorStack()
> // after
>. errors.AsError(errors.Wrap(err)).ErrorStack()
> ```
* v1.4.0 *BREAKING* v1.4.0 reverted all changes from v1.3.0 and is identical to v1.2.0

View file

@ -139,7 +139,6 @@ func WrapPrefix(e interface{}, prefix string, skip int) *Error {
}
// Errorf creates a new error with the given message. You can use it
// as a drop-in replacement for fmt.Errorf() to provide descriptive
// errors in return values.
@ -203,3 +202,8 @@ func (err *Error) TypeName() string {
}
return reflect.TypeOf(err.Err).String()
}
// Return the wrapped error (implements api for As function).
func (err *Error) Unwrap() error {
return err.Err
}

View file

@ -6,6 +6,11 @@ import (
baseErrors "errors"
)
// find error in any wrapped error
func As(err error, target interface{}) bool {
return baseErrors.As(err, target)
}
// Is detects whether the error is equal to a given error. Errors
// are considered equal by this function if they are matched by errors.Is
// or if their contained errors are matched through errors.Is

View file

@ -2,6 +2,41 @@
package errors
import (
"reflect"
)
type unwrapper interface {
Unwrap() error
}
// As assigns error or any wrapped error to the value target points
// to. If there is no value of the target type of target As returns
// false.
func As(err error, target interface{}) bool {
targetType := reflect.TypeOf(target)
for {
errType := reflect.TypeOf(err)
if errType == nil {
return false
}
if reflect.PtrTo(errType) == targetType {
reflect.ValueOf(target).Elem().Set(reflect.ValueOf(err))
return true
}
wrapped, ok := err.(unwrapper)
if ok {
err = wrapped.Unwrap()
} else {
return false
}
}
}
// Is detects whether the error is equal to a given error. Errors
// are considered equal by this function if they are the same object,
// or if they both contain the same error inside an errors.Error.
@ -19,4 +54,4 @@ func Is(e error, original error) bool {
}
return false
}
}

View file

@ -1,3 +1,6 @@
module github.com/go-errors/errors
go 1.14
// Was not API-compatible with earlier or later releases.
retract v1.3.0