Selaa lähdekoodia

ci: Add `nilnil` and `nilnesserr` lints (#4516)

ci: Add `nilnil` and `nilnesserr` lints  (#4516)

Find the code that returns nil even if it checks that the error is not nil.

https://golangci-lint.run/docs/linters/configuration/#nilerr

Checks that there is no simultaneous return of nil error and an invalid value.

https://golangci-lint.run/docs/linters/configuration/#nilnil
John Saigle 1 kuukausi sitten
vanhempi
sitoutus
e89d0e03cb

+ 2 - 0
.golangci.yml

@@ -26,6 +26,8 @@ linters:
     - loggercheck
     - loggercheck
     # Check for simple misspellings of words. 
     # Check for simple misspellings of words. 
     - misspell
     - misspell
+    - nilerr
+    - nilnesserr
     - noctx
     - noctx
     # Require explanations for nolint comments
     # Require explanations for nolint comments
     - nolintlint
     - nolintlint

+ 1 - 1
node/pkg/watchers/evm/ccq_backfill.go

@@ -263,7 +263,7 @@ func (w *Watcher) ccqBackfillGetBlocks(ctx context.Context, initialBlockNum uint
 	blocks := Blocks{}
 	blocks := Blocks{}
 	for i := range results {
 	for i := range results {
 		if results[i].err != nil {
 		if results[i].err != nil {
-			return nil, fmt.Errorf("failed to get block: %w", err)
+			return nil, fmt.Errorf("failed to get block: %w", results[i].err)
 		}
 		}
 
 
 		m := &results[i].result
 		m := &results[i].result

+ 3 - 3
node/pkg/watchers/evm/reobserve.go

@@ -51,7 +51,7 @@ func (w *Watcher) handleReobservationRequest(ctx context.Context, chainId vaa.Ch
 			pubErr := w.verifyAndPublish(msg, ctx, eth_common.BytesToHash(msg.TxID), receipt)
 			pubErr := w.verifyAndPublish(msg, ctx, eth_common.BytesToHash(msg.TxID), receipt)
 
 
 			if pubErr != nil {
 			if pubErr != nil {
-				w.logger.Error("Error when publishing message", zap.Error(err))
+				w.logger.Error("Error when publishing message", zap.Error(pubErr))
 			} else {
 			} else {
 				numObservations++
 				numObservations++
 			}
 			}
@@ -79,7 +79,7 @@ func (w *Watcher) handleReobservationRequest(ctx context.Context, chainId vaa.Ch
 				pubErr := w.verifyAndPublish(msg, ctx, eth_common.BytesToHash(msg.TxID), receipt)
 				pubErr := w.verifyAndPublish(msg, ctx, eth_common.BytesToHash(msg.TxID), receipt)
 
 
 				if pubErr != nil {
 				if pubErr != nil {
-					w.logger.Error("Error when publishing message", zap.Error(err))
+					w.logger.Error("Error when publishing message", zap.Error(pubErr))
 					// Avoid increasing the observations metrics for messages that weren't published.
 					// Avoid increasing the observations metrics for messages that weren't published.
 					continue
 					continue
 				}
 				}
@@ -125,7 +125,7 @@ func (w *Watcher) handleReobservationRequest(ctx context.Context, chainId vaa.Ch
 			pubErr := w.verifyAndPublish(msg, ctx, eth_common.BytesToHash(msg.TxID), receipt)
 			pubErr := w.verifyAndPublish(msg, ctx, eth_common.BytesToHash(msg.TxID), receipt)
 
 
 			if pubErr != nil {
 			if pubErr != nil {
-				w.logger.Error("Error when publishing message", zap.Error(err))
+				w.logger.Error("Error when publishing message", zap.Error(pubErr))
 			} else {
 			} else {
 				numObservations++
 				numObservations++
 			}
 			}

+ 1 - 0
node/pkg/watchers/ibc/watcher.go

@@ -530,6 +530,7 @@ func parseIbcReceivePublishEvent(logger *zap.Logger, desiredContract string, eve
 
 
 	str, err = attributes.GetAsString("action")
 	str, err = attributes.GetAsString("action")
 	if err != nil || str != "receive_publish" {
 	if err != nil || str != "receive_publish" {
+		//nolint:nilerr // Returning nil here just means that no `receive_publish` action exists. We don't want to continue processing in this case.
 		return nil, nil
 		return nil, nil
 	}
 	}
 
 

+ 1 - 1
node/pkg/watchers/near/poll.go

@@ -83,7 +83,7 @@ func (e *Watcher) ReadFinalChunksSince(logger *zap.Logger, ctx context.Context,
 
 
 	finalBlock, err := e.nearAPI.GetFinalBlock(ctx)
 	finalBlock, err := e.nearAPI.GetFinalBlock(ctx)
 	if err != nil {
 	if err != nil {
-		// We can suppress this error because this is equivalent to saying that we haven't found any blocks since.
+		//nolint:nilerr // We can suppress this error because this is equivalent to saying that we haven't found any blocks since.
 		return startHeight, nil
 		return startHeight, nil
 	}
 	}
 
 

+ 1 - 1
node/pkg/watchers/sui/watcher.go

@@ -583,7 +583,7 @@ func (e *Watcher) getLatestCheckpointSN(ctx context.Context, logger *zap.Logger)
 	if pErr != nil {
 	if pErr != nil {
 		logger.Error("Failed to ParseInt")
 		logger.Error("Failed to ParseInt")
 		p2p.DefaultRegistry.AddErrorCount(vaa.ChainIDSui, 1)
 		p2p.DefaultRegistry.AddErrorCount(vaa.ChainIDSui, 1)
-		return 0, fmt.Errorf("sui_getLatestCheckpointSequenceNumber failed to ParseInt, error: %w", err)
+		return 0, fmt.Errorf("sui_getLatestCheckpointSequenceNumber failed to ParseInt, error: %w", pErr)
 	}
 	}
 	return height, nil
 	return height, nil
 }
 }