Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(lib/babe): epoch error wrapping fixed up #2484

Merged
merged 1 commit into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion dot/state/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,9 @@ func (s *EpochState) HasEpochData(epoch uint64) (bool, error) {
return has, nil
}

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

Expand Down
6 changes: 3 additions & 3 deletions lib/babe/babe.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func (b *Service) initiate() {
func (b *Service) initiateAndGetEpochHandler(epoch uint64) (*epochHandler, error) {
epochData, err := b.initiateEpoch(epoch)
if err != nil {
return nil, fmt.Errorf("failed to initiate epoch %d: %w", epoch, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove epoch number?

Copy link
Contributor Author

@qdm12 qdm12 Apr 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's added in the initiateEpoch method (well in HasEpochData further down the call stack), so to avoid repeating the epoch number a bunch of times in the error.

Anyway, the function handling the argument should be the only one adding context to the error with it, not its callers.

return nil, fmt.Errorf("failed to initiate epoch: %w", err)
}

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

epoch = next
Expand All @@ -442,7 +442,7 @@ func (b *Service) handleEpoch(epoch uint64) (next uint64, err error) {
defer cancel()
b.epochHandler, err = b.initiateAndGetEpochHandler(epoch)
if err != nil {
return 0, fmt.Errorf("cannot initiate and get epoch handler for epoch %d: %w", epoch, err)
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
return 0, fmt.Errorf("cannot initiate and get epoch handler: %w", err)
}

// get start slot for current epoch
Expand Down
2 changes: 1 addition & 1 deletion lib/babe/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (b *Service) getEpochDataAndStartSlot(epoch uint64) (*epochData, uint64, er

has, err := b.epochState.HasEpochData(epoch)
if err != nil {
return nil, 0, fmt.Errorf("cannot check for epoch data for epoch %d: %w", epoch, err)
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
return nil, 0, fmt.Errorf("cannot check epoch state: %w", err)
}

if !has {
Expand Down