Skip to content

Commit 11b3e1b

Browse files
committed
Add errors.AsError() to get back that behaviour
1 parent 60174f7 commit 11b3e1b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,13 @@ everyone can benefit.
6666
This package is licensed under the MIT license, see LICENSE.MIT for details.
6767

6868
## Changelog
69-
* v1.1.0 updated to use go1.13's standard-library errors.Is method instead of == in errors.Is
69+
* v1.1.0 updated to use go1.13's standard-library errors.Is method instead of == in errors.Is
70+
* v1.2.0 added `errors.As` from the standard library.
71+
* v1.3.0 *BREAKING* updated error methods to return `error` instead of `*Error`.
72+
> Code that needs access to the underlying `*Error` can use the new errors.AsError(e)
73+
> ```
74+
> // before
75+
> errors.New(err).ErrorStack()
76+
> // after
77+
>. errors.AsError(errors.Wrap(err)).ErrorStack()
78+
> ```

error.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,10 @@ func (err *Error) TypeName() string {
207207
func (err *Error) Unwrap() error {
208208
return err.Err
209209
}
210+
211+
// AsError converts e to an *errors.Error.
212+
// If e does not already have a stacktrace attached, the current stack
213+
// will be added.
214+
func AsError(e error) *Error {
215+
return Wrap(e, 1).(*Error)
216+
}

0 commit comments

Comments
 (0)