File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed
Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change 66 hooks :
77 - id : yamlfmt
88 - repo : https://github.com/google/keep-sorted
9- rev : v0.7.0
9+ rev : v0.7.1
1010 hooks :
1111 - id : keep-sorted
1212 - repo : https://github.com/DavidAnson/markdownlint-cli2
Original file line number Diff line number Diff line change @@ -22,6 +22,10 @@ import "iter"
2222// It supports both single error unwrapping (`Unwrap() error`) and multi-error unwrapping (`Unwrap() []error`) mechanisms.
2323// Nil errors or nil results from unwrapping are skipped during traversal.
2424func DepthFirstErrorTree (root error ) iter.Seq [error ] {
25+ if root == nil {
26+ return iterNone [error ]
27+ }
28+
2529 return func (yield func (error ) bool ) {
2630 base := [4 ]error {root } // Allocated on the stack
2731 stack := base [:1 ]
@@ -30,10 +34,6 @@ func DepthFirstErrorTree(root error) iter.Seq[error] {
3034 err := stack [top ]
3135 stack = stack [:top ]
3236
33- if err == nil {
34- continue
35- }
36-
3737 if ! yield (err ) {
3838 return
3939 }
@@ -43,12 +43,18 @@ func DepthFirstErrorTree(root error) iter.Seq[error] {
4343 unwrap := x .Unwrap ()
4444 // Push children in reverse order to visit them in their original order (depth-first).
4545 for i := len (unwrap ) - 1 ; i >= 0 ; i -- {
46- stack = append (stack , unwrap [i ])
46+ if err := unwrap [i ]; err != nil {
47+ stack = append (stack , err )
48+ }
4749 }
4850
4951 case interface { Unwrap () error }:
50- stack = append (stack , x .Unwrap ())
52+ if err := x .Unwrap (); err != nil {
53+ stack = append (stack , err )
54+ }
5155 }
5256 }
5357 }
5458}
59+
60+ func iterNone [V any ](func (V ) bool ) {}
You can’t perform that action at this time.
0 commit comments