From 6f59c80d7392c978b13c9215b56344b0af73c7c6 Mon Sep 17 00:00:00 2001 From: ChengenH Date: Fri, 13 Dec 2024 16:00:02 +0800 Subject: [PATCH] refactor: unify the error handling methods in the crypto package that are different from the project style Signed-off-by: ChengenH --- frontend/schema/internal/reflectwalk/reflectwalk.go | 8 ++++---- frontend/schema/walk.go | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/frontend/schema/internal/reflectwalk/reflectwalk.go b/frontend/schema/internal/reflectwalk/reflectwalk.go index 9de94c87d1..9d5dee94ce 100644 --- a/frontend/schema/internal/reflectwalk/reflectwalk.go +++ b/frontend/schema/internal/reflectwalk/reflectwalk.go @@ -110,7 +110,7 @@ func walk(v reflect.Value, w interface{}) (err error) { if pointerV.Kind() == reflect.Interface { if iw, ok := w.(InterfaceWalker); ok { if err = iw.Interface(pointerV); err != nil { - if err == ErrSkipEntry { + if errors.Is(err, ErrSkipEntry) { // Skip the rest of this entry but clear the error return nil } @@ -124,7 +124,7 @@ func walk(v reflect.Value, w interface{}) (err error) { if pointerV.Kind() == reflect.Ptr { if pw, ok := w.(PointerValueWalker); ok { if err = pw.Pointer(pointerV); err != nil { - if err == ErrSkipEntry { + if errors.Is(err, ErrSkipEntry) { // Skip the rest of this entry but clear the error return nil } @@ -271,7 +271,7 @@ func walkStruct(v reflect.Value, w interface{}) (err error) { skip := false if sw, ok := w.(StructWalker); ok { err = sw.Struct(v) - if err == ErrSkipEntry { + if errors.Is(err, ErrSkipEntry) { skip = true err = nil } @@ -297,7 +297,7 @@ func walkStruct(v reflect.Value, w interface{}) (err error) { err = sw.StructField(sf, f) // SkipEntry just pretends this field doesn't even exist - if err == ErrSkipEntry { + if errors.Is(err, ErrSkipEntry) { continue } diff --git a/frontend/schema/walk.go b/frontend/schema/walk.go index d71c5981c4..67da96b679 100644 --- a/frontend/schema/walk.go +++ b/frontend/schema/walk.go @@ -1,6 +1,7 @@ package schema import ( + "errors" "fmt" "reflect" "strconv" @@ -20,7 +21,7 @@ func Walk(circuit interface{}, tLeaf reflect.Type, handler LeafHandler) (count L handler: handler, } err = reflectwalk.Walk(circuit, &w) - if err == reflectwalk.ErrSkipEntry { + if errors.Is(err, reflectwalk.ErrSkipEntry) { err = nil } count.Public = w.nbPublic