Skip to content

Commit 3f605f7

Browse files
committed
Cleanup; no more errors for empty db results
1 parent cdd0433 commit 3f605f7

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

internal/dblevel/client.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import (
1212
)
1313

1414
// todo change to `var NoEntryErr = errors.new("[no entry found]")`
15+
16+
// NoEntryErr was used to handle empty responses from level db
17+
//
18+
// Deprecated: Will probably not survive next rewrite. Bad design
1519
type NoEntryErr struct{}
1620

1721
func (e NoEntryErr) Error() string {
@@ -98,13 +102,14 @@ func retrieveByBlockHash(db *leveldb.DB, blockHash [32]byte, pair types.Pair) er
98102
if err != nil && !errors.Is(err, leveldb.ErrNotFound) { // todo this error probably exists as var/type somewhere
99103
logging.L.Err(err).Msg("error getting block hash")
100104
return err
101-
} else if err != nil && errors.Is(err, leveldb.ErrNotFound) { // todo this error probably exists as var/type somewhere
102-
// todo we don't need separate patterns if just return the errors anyways? or maybe just to avoid unnecessary logging
103-
return NoEntryErr{}
105+
} else if err != nil && errors.Is(err, leveldb.ErrNotFound) {
106+
return nil
104107
}
105108
if len(data) == 0 {
106-
// todo this should be a different type of error case
107-
return NoEntryErr{}
109+
// we do not return any errors anymore for empty results
110+
//empty results are to be expected now and then
111+
// only make error handling even more complicated
112+
return nil
108113
}
109114

110115
err = pair.DeSerialiseKey(blockHash[:])
@@ -133,13 +138,12 @@ func retrieveByBlockHeight(db *leveldb.DB, blockHeight uint32, pair types.Pair)
133138
if err != nil && err.Error() != "leveldb: not found" { // todo this error probably exists as var/type somewhere
134139
logging.L.Err(err).Msg("error getting block height")
135140
return err
136-
} else if err != nil && err.Error() == "leveldb: not found" { // todo this error probably exists as var/type somewhere
137-
return NoEntryErr{}
141+
} else if err != nil && errors.Is(err, leveldb.ErrNotFound) { // todo this error probably exists as var/type somewhere
142+
return nil
138143
}
139144

140145
if len(data) == 0 {
141-
// todo this should be a different type of error case
142-
return NoEntryErr{}
146+
return nil
143147
}
144148

145149
err = pair.DeSerialiseKey(buf.Bytes())

internal/server/v2/service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ func (s *OracleService) StreamBlockBatchSlim(
263263
req *pb.RangedBlockHeightRequest,
264264
stream pb.OracleService_StreamBlockBatchSlimServer,
265265
) error {
266+
logging.L.Info().Msgf("streaming slim batches from %d to %d", req.Start, req.End)
266267
for height := req.Start; height <= req.End; height++ {
267268
headerInv, err := dblevel.FetchByBlockHeightBlockHeaderInv(uint32(height))
268269
if err != nil {

0 commit comments

Comments
 (0)