refactor(core): use errors.Is for sentinel error comparisons in blockchain.go - #2552
refactor(core): use errors.Is for sentinel error comparisons in blockchain.go#2552gzliudan wants to merge 1 commit into
Conversation
…chain.go Replace direct == / != comparisons against sentinel errors (consensus.ErrPrunedAncestor, consensus.ErrFutureBlock, consensus.ErrUnknownAncestor, ErrKnownBlock, ErrStopPreparingBlock) with errors.Is, which also matches wrapped errors.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🟢 Approval recommended
The focused, mechanically consistent changes preserve current behavior while correctly supporting wrapped sentinel errors.
Pull request overview
Modernizes sentinel-error handling in blockchain insertion paths so wrapped errors are recognized correctly.
Changes:
- Replaces direct sentinel comparisons with
errors.Is. - Preserves negation when handling
ErrStopPreparingBlock.
File summaries
| File | Description |
|---|---|
core/blockchain.go |
Updates sentinel-error checks in block insertion and processing paths. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Description
Replace direct
==/!=comparisons against sentinel errors incore/blockchain.gowitherrors.Is, matching modern Go idiom (used elsewhere in this file, e.g.errors.Is(err, ErrGenesisAllocUnavailable)).errors.Isis behaviorally identical for these plainerrors.Newsentinels today, but also matches wrapped errors (fmt.Errorf("...: %w", err)), so future refactors that wrap these sentinels won't silently break insertion-path error handling.Changes
11 comparisons updated:
consensus.ErrPrunedAncestorinsertChain,insertSidechain,getResultBlockconsensus.ErrFutureBlockinsertChainconsensus.ErrUnknownAncestorinsertChainErrKnownBlockinsertChain,getResultBlockErrStopPreparingBlockgetResultBlock—err != ErrStopPreparingBlock→!errors.Is(err, ErrStopPreparingBlock)(negation preserved: only non-stop errors are reported as bad blocks)Untouched by design:
switch err { case ErrKnownBlock: ... }inprepareBlock(switch-case form,case nilbranch present).Testing
gofmt/goimportsclean,go vet ./core/cleanmake allbuildsgo test ./core/...— all passmake test— full suite, 0 FAILmake tidy/make generate— no changes