Skip to content

Commit 7619f70

Browse files
committed
fix some issues in file walker
- add Unwrap() and Cause() to the error type (to make it work with errors.As()) - change determination of struct fields (to avoid double passes in case of embedded structs)
1 parent 5db03be commit 7619f70

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

internal/walk/walk.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ func (e walkError) Error() string {
4040
return fmt.Sprintf("/%s: %s", strings.Join(e.path, "/"), e.err)
4141
}
4242

43+
func (e walkError) Unwrap() error {
44+
return e.err
45+
}
46+
47+
func (e walkError) Cause() error {
48+
return e.err
49+
}
50+
4351
func walk(v reflect.Value, path []string, tag reflect.StructTag, f WalkFunc) (errs []error) {
4452
t := v.Type()
4553

@@ -74,7 +82,8 @@ func walk(v reflect.Value, path []string, tag reflect.StructTag, f WalkFunc) (er
7482
}
7583
case reflect.Struct:
7684
callback()
77-
for _, field := range reflect.VisibleFields(t) {
85+
for i := 0; i < t.NumField(); i++ {
86+
field := t.Field(i)
7887
if field.IsExported() {
7988
errs = append(errs, walk(v.FieldByIndex(field.Index), append(path, field.Name), field.Tag, f)...)
8089
}

0 commit comments

Comments
 (0)