From f979f1d14305a70c863c2557a608dd2efbadd587 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sun, 24 Mar 2024 20:06:00 +0800 Subject: [PATCH] =?UTF-8?q?KV=E5=AD=98=E5=82=A8=E8=BF=AD=E4=BB=A3=E5=99=A8?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0panic=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/utils/kvstore/query.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/utils/kvstore/query.go b/internal/utils/kvstore/query.go index 80c3475..a3fff24 100644 --- a/internal/utils/kvstore/query.go +++ b/internal/utils/kvstore/query.go @@ -5,6 +5,7 @@ package kvstore import ( "bytes" "errors" + "fmt" ) type DataType = int @@ -162,7 +163,17 @@ func (this *Query[T]) FieldOffset(fieldOffset []byte) *Query[T] { // return this //} -func (this *Query[T]) FindAll(fn IteratorFunc[T]) error { +func (this *Query[T]) FindAll(fn IteratorFunc[T]) (err error) { + defer func() { + var panicErr = recover() + if panicErr != nil { + resultErr, ok := panicErr.(error) + if ok { + err = fmt.Errorf("execute query failed: %w", resultErr) + } + } + }() + if this.tx != nil { defer func() { _ = this.tx.Close()