Skip to content

ci: Add govet shadow detection#4722

Open
johnsaigle wants to merge 5 commits intowormhole-foundation:mainfrom
johnsaigle:govet-shadow
Open

ci: Add govet shadow detection#4722
johnsaigle wants to merge 5 commits intowormhole-foundation:mainfrom
johnsaigle:govet-shadow

Conversation

@johnsaigle
Copy link
Copy Markdown
Contributor

Augment our linting set-up with shadow detection. In practice, most of our variable shadowing involves reusing err within the same scope. Even though this is pretty common in Go, we've had a few small bugs where the wrong error was logged, or where this pattern ended up returning a nil error.

To address this, shadowing is now blocked generally in the Go code.

Comment on lines -120 to -122
- ./+governor.tokenConfigEntry$
# TODO: MessagePublications _should_ be exhaustive but this will require many changes.
- ./_common.MessagePublication$
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They're both based off of main, but #4720 should be the one that ultimately decides the MessagePublication behaviour.

mdulin2
mdulin2 previously approved these changes Mar 18, 2026
@mdulin2
Copy link
Copy Markdown
Contributor

mdulin2 commented Mar 18, 2026

Good lint to add!

bemic
bemic previously approved these changes Mar 25, 2026
Copy link
Copy Markdown
Contributor

@bemic bemic left a comment

Choose a reason for hiding this comment

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

The code is better to read with this one. I like that

johnsaigle and others added 4 commits March 26, 2026 17:27
Augment our linting set-up with shadow detection. In practice, most of
our variable shadowing involves reusing `err` within the same scope.
Even though this is pretty common in Go, we've had a few small bugs
where the wrong error was logged, or where this pattern ended up
returning a nil error.

To address this, shadowing is now blocked generally in the Go code.
if err != nil {
genErr := devnet.GenerateAndStoreDevnetGuardianKey(*guardianKeyPath)
if genErr != nil {
logger.Fatal("failed to generate devnet guardian key", zap.Error(err))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this be zap.Error(genErr)?

//nolint:noctx // TODO: this should be refactored to use context.
_, err := net.LookupIP(firstGuardianName)
if err == nil {
_, resolveErr := net.LookupIP(firstGuardianName)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess this isn't meant to change the original behaviour. But would it be useful logging the error, while we are here?

if len(insolventAssets) > 0 {
for _, msgPub := range *receipt.MessagePublications {
msgID, err := tv.MsgID(msgPub)
msgID2, err := tv.MsgID(msgPub)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand some of these changes. Why rename this to msgID2? It's scoped in its own block, similar to msgID and msgID2 (another rename) earlier?

@johnsaigle johnsaigle dismissed stale reviews from bemic and mdulin2 via 28f7285 March 27, 2026 13:29
@johnsaigle
Copy link
Copy Markdown
Contributor Author

@pleasew8t I changed some of the variable names, hopefully that's more clear. The general idea is to forbid variable shadowing in the codebase, even if current instances of shadowing are correct right now.

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.

5 participants