KV存储迭代器增加panic处理

This commit is contained in:
刘祥超
2024-03-24 20:06:00 +08:00
parent f425b0faf6
commit 32a3b2db2e

View File

@@ -5,6 +5,7 @@ package kvstore
import ( import (
"bytes" "bytes"
"errors" "errors"
"fmt"
) )
type DataType = int type DataType = int
@@ -162,7 +163,17 @@ func (this *Query[T]) FieldOffset(fieldOffset []byte) *Query[T] {
// return this // 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 { if this.tx != nil {
defer func() { defer func() {
_ = this.tx.Close() _ = this.tx.Close()