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

indexers: update indexer error types. #2770

Merged
merged 1 commit into from Dec 5, 2021

Conversation

dnldd
Copy link
Member

@dnldd dnldd commented Oct 25, 2021

This updates the wire error types to leverage go 1.13 errors.Is/As functionality as well as confirm to the error infrastructure best practices outlined in #2181.

blockchain/indexers/error.go Outdated Show resolved Hide resolved
Copy link
Member

@JoeGruffins JoeGruffins left a comment

Choose a reason for hiding this comment

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

Looks good to me, but are you sure about returning in the switch?

Comment on lines 1201 to 1216
if err != nil {
log.Errorf("%s: unable to disconnect block: %v", idx.Name(), err)
msg := fmt.Sprintf("%s: unable to disconnect block: %v",
idx.Name(), err)
return indexerError(ErrDisconnectBlock, msg)
}

// Remove the associated spend consumer dependency for the disconnected
// block.
err = idx.Queryer().RemoveSpendConsumerDependency(dbTx, ntfn.Block.Hash(),
idx.consumer.id)
if err != nil {
log.Errorf("%s: unable to remove spend consumer dependency "+
"for block %s: %v", idx.Name(), ntfn.Block.Hash(), err)
msg := fmt.Sprintf("%s: unable to remove spend consumer "+
"dependency for block %s: %v", idx.Name(),
ntfn.Block.Hash(), err)
return indexerError(ErrDisconnectBlock, msg)
}
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if intended, but this changes the behavior to return rather than just log errors and the update tip below is no longer always called.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes it's intended, if disconnecting a block fails for the index it'd be inaccurate to update its tip. Also to keep things synchronized, if removing a spend consumer dependency generates an error for an index it should return.

blockchain/indexers/error.go Outdated Show resolved Hide resolved
ErrBlockNotOnMainChain = ErrorKind("ErrBlockNotOnMainChain")
)

// Error satisfies the error interface and prints human-readable errors.
Copy link
Member

Choose a reason for hiding this comment

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

You can also check with var _ error = ErrorKind("") but I guess it will never change with just the one method.

Copy link
Member Author

Choose a reason for hiding this comment

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

Deferring this for later if we decide it is better to be explicit about implementing the error interface throughout the codebase.

This updates the wire error types to leverage go 1.13 errors.Is/As
functionality as well as confirm to the error infrastructure best
practices outlined in decred#2181.
@davecgh davecgh merged commit daf6c25 into decred:master Dec 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants