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

lint: enable govet shadow linter and resolve linter warnings #5261

Merged
merged 10 commits into from
Jun 1, 2023
10 changes: 10 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ linters-settings:
# We do this 121 times and never check the error.
- (*github.com/spf13/cobra.Command).MarkFlagRequired
govet:
check-shadowing: true
settings:
shadow:
# explanation of strict vs non-strict:
# https://github.com/golang/tools/blob/v0.7.0/go/analysis/passes/shadow/shadow.go#L104-L122
strict: false
printf:
# Comma-separated list of print function names to check (in addition to default, see `go tool vet help printf`).
# Default: []
Expand Down Expand Up @@ -118,6 +123,11 @@ issues:
# - revive
- staticcheck
- typecheck
# allow shadowing in test code
- path: _test\.go
linters:
- govet
text: "shadows declaration at line"
# Ignore missing parallel tests in existing packages
- path: ^agreement.*_test\.go
linters:
Expand Down
6 changes: 3 additions & 3 deletions agreement/demux.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ func (d *demux) tokenizeMessages(ctx context.Context, net Network, tag protocol.
if err != nil {
warnMsg := fmt.Sprintf("disconnecting from peer: error decoding message tagged %v: %v", tag, err)
// check protocol version
cv, err := d.ledger.ConsensusVersion(d.ledger.NextRound())
if err == nil {
if _, ok := config.Consensus[cv]; !ok {
cv, cvErr := d.ledger.ConsensusVersion(d.ledger.NextRound())
if cvErr == nil {
if _, found := config.Consensus[cv]; !found {
warnMsg = fmt.Sprintf("received proposal message was ignored. The node binary doesn't support the next network consensus (%v) and would no longer be able to process agreement messages", cv)
}
}
Expand Down
12 changes: 6 additions & 6 deletions agreement/pseudonode.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,17 +295,17 @@ func (n asyncPseudonode) makeProposals(round basics.Round, period period, accoun
votes := make([]unauthenticatedVote, 0, len(accounts))
proposals := make([]proposal, 0, len(accounts))
for _, acc := range accounts {
payload, proposal, err := proposalForBlock(acc.Account, acc.VRF, ve, period, n.ledger)
if err != nil {
n.log.Errorf("pseudonode.makeProposals: could not create proposal for block (address %v): %v", acc.Account, err)
payload, proposal, pErr := proposalForBlock(acc.Account, acc.VRF, ve, period, n.ledger)
if pErr != nil {
n.log.Errorf("pseudonode.makeProposals: could not create proposal for block (address %v): %v", acc.Account, pErr)
continue
}

// attempt to make the vote
rv := rawVote{Sender: acc.Account, Round: round, Period: period, Step: propose, Proposal: proposal}
uv, err := makeVote(rv, acc.VotingSigner(), acc.VRF, n.ledger)
if err != nil {
n.log.Warnf("pseudonode.makeProposals: could not create vote: %v", err)
uv, vErr := makeVote(rv, acc.VotingSigner(), acc.VRF, n.ledger)
if vErr != nil {
n.log.Warnf("pseudonode.makeProposals: could not create vote: %v", vErr)
continue
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/algocfg/profileCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ var setProfileCmd = &cobra.Command{
reportErrorf("%v", err)
}
file := filepath.Join(dataDir, config.ConfigFilename)
if _, err := os.Stat(file); !forceUpdate && err == nil {
if _, statErr := os.Stat(file); !forceUpdate && statErr == nil {
fmt.Printf("A config.json file already exists for this data directory. Would you like to overwrite it? (Y/n)")
reader := bufio.NewReader(os.Stdin)
resp, err := reader.ReadString('\n')
resp, readErr := reader.ReadString('\n')
resp = strings.TrimSpace(resp)
if err != nil {
reportErrorf("Failed to read response: %v", err)
if readErr != nil {
reportErrorf("Failed to read response: %v", readErr)
}
if strings.ToLower(resp) == "n" {
reportInfof("Exiting without overwriting existing config.")
Expand Down
4 changes: 2 additions & 2 deletions cmd/catchpointdump/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ func loadAndDump(addr string, tarFile string, genesisInitState ledgercore.InitSt
}

defer func() {
if err := deleteLedgerFiles(!loadOnly); err != nil {
reportWarnf("Error deleting ledger files: %v", err)
if delErr := deleteLedgerFiles(!loadOnly); delErr != nil {
reportWarnf("Error deleting ledger files: %v", delErr)
}
}()
defer l.Close()
Expand Down
10 changes: 5 additions & 5 deletions cmd/goal/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,16 +948,16 @@ No --delete-input flag specified, exiting without installing key.`)
reportErrorf(errorRequestFail, err)
}
// In an abundance of caution, check for ourselves that the key has been installed.
if err := client.VerifyParticipationKey(time.Minute, addResponse.PartId); err != nil {
err = fmt.Errorf("unable to verify key installation. Verify key installation with 'goal account partkeyinfo' and delete '%s', or retry the command. Error: %w", partKeyFile, err)
reportErrorf(errorRequestFail, err)
if vErr := client.VerifyParticipationKey(time.Minute, addResponse.PartId); vErr != nil {
vErr = fmt.Errorf("unable to verify key installation. Verify key installation with 'goal account partkeyinfo' and delete '%s', or retry the command. Error: %w", partKeyFile, vErr)
reportErrorf(errorRequestFail, vErr)
}

reportInfof("Participation key installed successfully, Participation ID: %s\n", addResponse.PartId)

// Delete partKeyFile
if nil != os.Remove(partKeyFile) {
reportErrorf("An error occurred while removing the partkey file, please delete it manually: %s", err)
if osErr := os.Remove(partKeyFile); osErr != nil {
jannotti marked this conversation as resolved.
Show resolved Hide resolved
reportErrorf("An error occurred while removing the partkey file, please delete it manually: %s", osErr)
}
},
}
Expand Down
138 changes: 69 additions & 69 deletions cmd/goal/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,14 @@ var createAppCmd = &cobra.Command{
if outFilename == "" {
// Broadcast
wh, pw := ensureWalletHandleMaybePassword(dataDir, walletName, true)
signedTxn, err := client.SignTransactionWithWalletAndSigner(wh, pw, signerAddress, tx)
if err != nil {
reportErrorf(errorSigningTX, err)
signedTxn, err2 := client.SignTransactionWithWalletAndSigner(wh, pw, signerAddress, tx)
if err2 != nil {
reportErrorf(errorSigningTX, err2)
}

txid, err := client.BroadcastTransaction(signedTxn)
if err != nil {
reportErrorf(errorBroadcastingTX, err)
txid, err2 := client.BroadcastTransaction(signedTxn)
if err2 != nil {
reportErrorf(errorBroadcastingTX, err2)
}

reportInfof("Attempting to create app (approval size %d, hash %v; clear size %d, hash %v)", len(approvalProg), crypto.HashObj(logic.Program(approvalProg)), len(clearProg), crypto.HashObj(logic.Program(clearProg)))
Expand Down Expand Up @@ -559,23 +559,23 @@ var updateAppCmd = &cobra.Command{
// Broadcast or write transaction to file
if outFilename == "" {
wh, pw := ensureWalletHandleMaybePassword(dataDir, walletName, true)
signedTxn, err := client.SignTransactionWithWalletAndSigner(wh, pw, signerAddress, tx)
if err != nil {
reportErrorf(errorSigningTX, err)
signedTxn, err2 := client.SignTransactionWithWalletAndSigner(wh, pw, signerAddress, tx)
if err2 != nil {
reportErrorf(errorSigningTX, err2)
}

txid, err := client.BroadcastTransaction(signedTxn)
if err != nil {
reportErrorf(errorBroadcastingTX, err)
txid, err2 := client.BroadcastTransaction(signedTxn)
if err2 != nil {
reportErrorf(errorBroadcastingTX, err2)
}

reportInfof("Attempting to update app (approval size %d, hash %v; clear size %d, hash %v)", len(approvalProg), crypto.HashObj(logic.Program(approvalProg)), len(clearProg), crypto.HashObj(logic.Program(clearProg)))
reportInfof("Issued transaction from account %s, txid %s (fee %d)", tx.Sender, txid, tx.Fee.Raw)

if !noWaitAfterSend {
_, err = waitForCommit(client, txid, lv)
if err != nil {
reportErrorf(err.Error())
_, err2 = waitForCommit(client, txid, lv)
if err2 != nil {
reportErrorf(err2.Error())
}
}
} else {
Expand Down Expand Up @@ -629,23 +629,23 @@ var optInAppCmd = &cobra.Command{
// Broadcast or write transaction to file
if outFilename == "" {
wh, pw := ensureWalletHandleMaybePassword(dataDir, walletName, true)
signedTxn, err := client.SignTransactionWithWalletAndSigner(wh, pw, signerAddress, tx)
if err != nil {
reportErrorf(errorSigningTX, err)
signedTxn, err2 := client.SignTransactionWithWalletAndSigner(wh, pw, signerAddress, tx)
if err2 != nil {
reportErrorf(errorSigningTX, err2)
}

txid, err := client.BroadcastTransaction(signedTxn)
if err != nil {
reportErrorf(errorBroadcastingTX, err)
txid, err2 := client.BroadcastTransaction(signedTxn)
if err2 != nil {
reportErrorf(errorBroadcastingTX, err2)
}

// Report tx details to user
reportInfof("Issued transaction from account %s, txid %s (fee %d)", tx.Sender, txid, tx.Fee.Raw)

if !noWaitAfterSend {
_, err = waitForCommit(client, txid, lv)
if err != nil {
reportErrorf(err.Error())
_, err2 = waitForCommit(client, txid, lv)
if err2 != nil {
reportErrorf(err2.Error())
}
}
} else {
Expand Down Expand Up @@ -699,23 +699,23 @@ var closeOutAppCmd = &cobra.Command{
// Broadcast or write transaction to file
if outFilename == "" {
wh, pw := ensureWalletHandleMaybePassword(dataDir, walletName, true)
signedTxn, err := client.SignTransactionWithWalletAndSigner(wh, pw, signerAddress, tx)
if err != nil {
reportErrorf(errorSigningTX, err)
signedTxn, err2 := client.SignTransactionWithWalletAndSigner(wh, pw, signerAddress, tx)
if err2 != nil {
reportErrorf(errorSigningTX, err2)
}

txid, err := client.BroadcastTransaction(signedTxn)
if err != nil {
reportErrorf(errorBroadcastingTX, err)
txid, err2 := client.BroadcastTransaction(signedTxn)
if err2 != nil {
reportErrorf(errorBroadcastingTX, err2)
}

// Report tx details to user
reportInfof("Issued transaction from account %s, txid %s (fee %d)", tx.Sender, txid, tx.Fee.Raw)

if !noWaitAfterSend {
_, err = waitForCommit(client, txid, lv)
if err != nil {
reportErrorf(err.Error())
_, err2 = waitForCommit(client, txid, lv)
if err2 != nil {
reportErrorf(err2.Error())
}
}
} else {
Expand Down Expand Up @@ -769,23 +769,23 @@ var clearAppCmd = &cobra.Command{
// Broadcast or write transaction to file
if outFilename == "" {
wh, pw := ensureWalletHandleMaybePassword(dataDir, walletName, true)
signedTxn, err := client.SignTransactionWithWalletAndSigner(wh, pw, signerAddress, tx)
if err != nil {
reportErrorf(errorSigningTX, err)
signedTxn, err2 := client.SignTransactionWithWalletAndSigner(wh, pw, signerAddress, tx)
if err2 != nil {
reportErrorf(errorSigningTX, err2)
}

txid, err := client.BroadcastTransaction(signedTxn)
if err != nil {
reportErrorf(errorBroadcastingTX, err)
txid, err2 := client.BroadcastTransaction(signedTxn)
if err2 != nil {
reportErrorf(errorBroadcastingTX, err2)
}

// Report tx details to user
reportInfof("Issued transaction from account %s, txid %s (fee %d)", tx.Sender, txid, tx.Fee.Raw)

if !noWaitAfterSend {
_, err = waitForCommit(client, txid, lv)
if err != nil {
reportErrorf(err.Error())
_, err2 = waitForCommit(client, txid, lv)
if err2 != nil {
reportErrorf(err2.Error())
}
}
} else {
Expand Down Expand Up @@ -839,23 +839,23 @@ var callAppCmd = &cobra.Command{
// Broadcast or write transaction to file
if outFilename == "" {
wh, pw := ensureWalletHandleMaybePassword(dataDir, walletName, true)
signedTxn, err := client.SignTransactionWithWalletAndSigner(wh, pw, signerAddress, tx)
if err != nil {
reportErrorf(errorSigningTX, err)
signedTxn, err2 := client.SignTransactionWithWalletAndSigner(wh, pw, signerAddress, tx)
if err2 != nil {
reportErrorf(errorSigningTX, err2)
}

txid, err := client.BroadcastTransaction(signedTxn)
if err != nil {
reportErrorf(errorBroadcastingTX, err)
txid, err2 := client.BroadcastTransaction(signedTxn)
if err2 != nil {
reportErrorf(errorBroadcastingTX, err2)
}

// Report tx details to user
reportInfof("Issued transaction from account %s, txid %s (fee %d)", tx.Sender, txid, tx.Fee.Raw)

if !noWaitAfterSend {
_, err = waitForCommit(client, txid, lv)
if err != nil {
reportErrorf(err.Error())
_, err2 = waitForCommit(client, txid, lv)
if err2 != nil {
reportErrorf(err2.Error())
}
}
} else {
Expand Down Expand Up @@ -909,23 +909,23 @@ var deleteAppCmd = &cobra.Command{
// Broadcast or write transaction to file
if outFilename == "" {
wh, pw := ensureWalletHandleMaybePassword(dataDir, walletName, true)
signedTxn, err := client.SignTransactionWithWalletAndSigner(wh, pw, signerAddress, tx)
if err != nil {
reportErrorf(errorSigningTX, err)
signedTxn, err2 := client.SignTransactionWithWalletAndSigner(wh, pw, signerAddress, tx)
if err2 != nil {
reportErrorf(errorSigningTX, err2)
}

txid, err := client.BroadcastTransaction(signedTxn)
if err != nil {
reportErrorf(errorBroadcastingTX, err)
txid, err2 := client.BroadcastTransaction(signedTxn)
if err2 != nil {
reportErrorf(errorBroadcastingTX, err2)
}

// Report tx details to user
reportInfof("Issued transaction from account %s, txid %s (fee %d)", tx.Sender, txid, tx.Fee.Raw)

if !noWaitAfterSend {
_, err = waitForCommit(client, txid, lv)
if err != nil {
reportErrorf(err.Error())
_, err2 = waitForCommit(client, txid, lv)
if err2 != nil {
reportErrorf(err2.Error())
}
}
} else {
Expand Down Expand Up @@ -1314,9 +1314,9 @@ var methodAppCmd = &cobra.Command{

var retType *abi.Type
if retTypeStr != abi.VoidReturnType {
theRetType, err := abi.TypeOf(retTypeStr)
if err != nil {
reportErrorf("cannot cast %s to abi type: %v", retTypeStr, err)
theRetType, typeErr := abi.TypeOf(retTypeStr)
if typeErr != nil {
reportErrorf("cannot cast %s to abi type: %v", retTypeStr, typeErr)
}
retType = &theRetType
}
Expand Down Expand Up @@ -1405,9 +1405,9 @@ var methodAppCmd = &cobra.Command{
txnGroup = append(txnGroup, appCallTxn)
if len(txnGroup) > 1 {
// Only if transaction arguments are present, assign group ID
groupID, err := client.GroupID(txnGroup)
if err != nil {
reportErrorf("Cannot assign transaction group ID: %s", err)
groupID, gidErr := client.GroupID(txnGroup)
if gidErr != nil {
reportErrorf("Cannot assign transaction group ID: %s", gidErr)
}
for i := range txnGroup {
txnGroup[i].Group = groupID
Expand All @@ -1432,9 +1432,9 @@ var methodAppCmd = &cobra.Command{
continue
}

signedTxn, err := createSignedTransaction(client, shouldSign, dataDir, walletName, unsignedTxn, txnFromArgs.AuthAddr)
if err != nil {
reportErrorf(errorSigningTX, err)
signedTxn, signErr := createSignedTransaction(client, shouldSign, dataDir, walletName, unsignedTxn, txnFromArgs.AuthAddr)
if signErr != nil {
reportErrorf(errorSigningTX, signErr)
}

signedTxnGroup = append(signedTxnGroup, signedTxn)
Expand Down
Loading