KV存储迭代器增加panic处理

This commit is contained in:
GoEdgeLab
2024-03-24 20:06:00 +08:00
parent c2dc5fef28
commit f979f1d143

View File

@@ -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()