Skip to content

Commit c053dea

Browse files
authored
fix(lib/babe): epoch context error wrapping (#2484)
1 parent 89c32ae commit c053dea

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

dot/state/epoch.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ func (s *EpochState) HasEpochData(epoch uint64) (bool, error) {
323323
return has, nil
324324
}
325325

326-
if !errors.Is(chaindb.ErrKeyNotFound, err) {
326+
// we can have `has == false` and `err == nil`
327+
// so ensure the error is not nil in the condition below.
328+
if err != nil && !errors.Is(chaindb.ErrKeyNotFound, err) {
327329
return false, fmt.Errorf("cannot check database for epoch key %d: %w", epoch, err)
328330
}
329331

lib/babe/babe.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ func (b *Service) initiate() {
399399
func (b *Service) initiateAndGetEpochHandler(epoch uint64) (*epochHandler, error) {
400400
epochData, err := b.initiateEpoch(epoch)
401401
if err != nil {
402-
return nil, fmt.Errorf("failed to initiate epoch %d: %w", epoch, err)
402+
return nil, fmt.Errorf("failed to initiate epoch: %w", err)
403403
}
404404

405405
logger.Debugf("initiated epoch with threshold %s, randomness 0x%x and authorities %v",
@@ -430,7 +430,7 @@ func (b *Service) runEngine() error {
430430
if errors.Is(err, errServicePaused) || errors.Is(err, context.Canceled) {
431431
return nil
432432
} else if err != nil {
433-
return err
433+
return fmt.Errorf("cannot handle epoch: %w", err)
434434
}
435435

436436
epoch = next
@@ -442,7 +442,7 @@ func (b *Service) handleEpoch(epoch uint64) (next uint64, err error) {
442442
defer cancel()
443443
b.epochHandler, err = b.initiateAndGetEpochHandler(epoch)
444444
if err != nil {
445-
return 0, fmt.Errorf("cannot initiate and get epoch handler for epoch %d: %w", epoch, err)
445+
return 0, fmt.Errorf("cannot initiate and get epoch handler: %w", err)
446446
}
447447

448448
// get start slot for current epoch

lib/babe/epoch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (b *Service) getEpochDataAndStartSlot(epoch uint64) (*epochData, uint64, er
9292

9393
has, err := b.epochState.HasEpochData(epoch)
9494
if err != nil {
95-
return nil, 0, fmt.Errorf("cannot check for epoch data for epoch %d: %w", epoch, err)
95+
return nil, 0, fmt.Errorf("cannot check epoch state: %w", err)
9696
}
9797

9898
if !has {

0 commit comments

Comments
 (0)