Skip to content

fix(store): return the error from indexEventByHash in IndexEvent - #563

Open
0xrlawrence wants to merge 1 commit into
canopy-network:mainfrom
0xrlawrence:fix/indexevent-swallowed-error
Open

fix(store): return the error from indexEventByHash in IndexEvent#563
0xrlawrence wants to merge 1 commit into
canopy-network:mainfrom
0xrlawrence:fix/indexevent-swallowed-error

Conversation

@0xrlawrence

Copy link
Copy Markdown

Description

IndexEvent assigned the error from indexEventByHash and then overwrote it on the next call without ever checking it:

hashKey, err := t.indexEventByHash(e)
heightAndIndexKey := t.eventHeightAndIndexKey(e.Height, uint64(index))
if err = t.indexEventByHeightAndIndex(heightAndIndexKey, hashKey); err != nil {

If the primary hash index write failed, the failure was silently discarded. The function then carried on writing the height, chainId and address indexes, all pointing at a hashKey that was never persisted — leaving dangling secondary index entries and reporting success to the caller.

staticcheck flagged this as SA4006.

Changes Made

  • Check the error from indexEventByHash before it is reassigned, and return early.

Testing

  • go build ./...
  • go test ./store/ passes
  • staticcheck no longer reports SA4006 in store/indexer.go

🤖 Generated with Claude Code

IndexEvent assigned the error from indexEventByHash to err and then
overwrote it on the next call without ever checking it:

    hashKey, err := t.indexEventByHash(e)
    heightAndIndexKey := t.eventHeightAndIndexKey(...)
    if err = t.indexEventByHeightAndIndex(...); err != nil {

If the primary hash index write failed, the failure was discarded and the
function carried on writing the height, chainId and address indexes
pointing at a hashKey that was never persisted, leaving the indexer with
dangling secondary index entries and reporting success.

Check the error before it is reassigned. staticcheck flagged this as
SA4006.
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.

1 participant