Skip to content

Commit

Permalink
refactor(store): add missing error checks in store (#17794)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Sep 20, 2023
1 parent 86ab989 commit 22925c7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 3 additions & 1 deletion store/iavl/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,9 @@ func (st *Store) Query(req *types.RequestQuery) (res *types.ResponseQuery, err e
for ; iterator.Valid(); iterator.Next() {
pairs.Pairs = append(pairs.Pairs, kv.Pair{Key: iterator.Key(), Value: iterator.Value()})
}
iterator.Close()
if err := iterator.Close(); err != nil {
panic(fmt.Errorf("failed to close iterator: %w", err))
}

bz, err := pairs.Marshal()
if err != nil {
Expand Down
12 changes: 9 additions & 3 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,9 @@ func deleteKVStore(kv types.KVStore) error {
keys = append(keys, itr.Key())
itr.Next()
}
itr.Close()
if err := itr.Close(); err != nil {
return err
}

for _, k := range keys {
kv.Delete(k)
Expand All @@ -330,7 +332,9 @@ func moveKVStoreData(oldDB, newDB types.KVStore) error {
newDB.Set(itr.Key(), itr.Value())
itr.Next()
}
itr.Close()
if err := itr.Close(); err != nil {
return err
}

// then delete the old store
return deleteKVStore(oldDB)
Expand Down Expand Up @@ -1106,7 +1110,9 @@ func (rs *Store) GetCommitInfo(ver int64) (*types.CommitInfo, error) {
func (rs *Store) flushMetadata(db dbm.DB, version int64, cInfo *types.CommitInfo) {
rs.logger.Debug("flushing metadata", "height", version)
batch := db.NewBatch()
defer batch.Close()
defer func() {
_ = batch.Close()
}()

if cInfo != nil {
flushCommitInfo(batch, version, cInfo)
Expand Down
2 changes: 1 addition & 1 deletion store/tracekv/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,6 @@ func writeOperation(w io.Writer, op operation, tc types.TraceContext, key, value

_, err = io.WriteString(w, "\n")
if err != nil {
panic(err)
panic(errors.Wrap(err, "failed to write newline"))
}
}

0 comments on commit 22925c7

Please sign in to comment.