File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,9 @@ type WalkFunc func(error)
2121// wrapped error in addition to the wrapper itself. Since all the top-level
2222// functions in errwrap use Walk, this means that all those functions work
2323// with your custom type.
24+ //
25+ // Note: since Go 1.20 wrappers should instead implement Unwrap() []error
26+ // as documented in package [errors].
2427type Wrapper interface {
2528 WrappedErrors () []error
2629}
@@ -150,9 +153,15 @@ func Walk(err error, cb WalkFunc) {
150153 for _ , err := range e .WrappedErrors () {
151154 Walk (err , cb )
152155 }
153- case interface { Unwrap () error }:
156+ case interface { Unwrap () error }: // Go 1.13
154157 cb (err )
155158 Walk (e .Unwrap (), cb )
159+ case interface { Unwrap () []error }: // Go 1.20
160+ cb (err )
161+
162+ for _ , err := range e .Unwrap () {
163+ Walk (err , cb )
164+ }
156165 default :
157166 cb (err )
158167 }
You can’t perform that action at this time.
0 commit comments