From fc14aa4e750d5399122cbb51a12683a650888303 Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Sun, 19 Nov 2023 16:13:10 -0800 Subject: [PATCH] badger: log instead of panicing --- persist/badger/cids.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/persist/badger/cids.go b/persist/badger/cids.go index 651b3dd..e982887 100644 --- a/persist/badger/cids.go +++ b/persist/badger/cids.go @@ -7,6 +7,7 @@ import ( "github.com/dgraph-io/badger/v4" "github.com/ipfs/go-cid" "go.sia.tech/fsd/sia" + "go.uber.org/zap" ) // HasBlock returns true if the CID is in the store @@ -62,15 +63,22 @@ func (s *Store) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) { ch := make(chan cid.Cid) go func() { + log := s.log.Named("allKeysChan") _ = s.db.View(func(txn *badger.Txn) error { it := txn.NewIterator(badger.IteratorOptions{}) defer it.Close() for it.Rewind(); it.Valid(); it.Next() { + key := string(it.Item().Key()) + cid, err := cid.Parse(key) + if err != nil { + log.Error("failed to parse cid", zap.String("key", key)) + continue + } select { case <-ctx.Done(): return ctx.Err() - case ch <- cid.MustParse(string(it.Item().Key())): + case ch <- cid: } } return nil