Skip to content

Commit 95c15aa

Browse files
committed
Prepare 0.0.4
Signed-off-by: Oliver Eikemeier <eikemeier@fillmore-labs.com>
1 parent e89cedc commit 95c15aa

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ repos:
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

depthfirst.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff 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.
2424
func 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) {}

0 commit comments

Comments
 (0)