Skip to content

Commit 48a3d56

Browse files
authored
Merge pull request #8503 from ffranr/fix-err-wrap
Correct `fmt.Errorf` error wrapping instances
2 parents b234658 + e0358df commit 48a3d56

File tree

106 files changed

+438
-396
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+438
-396
lines changed

.golangci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ run:
3030
- integration
3131

3232
linters-settings:
33+
errorlint:
34+
# Check for incorrect fmt.Errorf error wrapping.
35+
errorf: true
36+
3337
govet:
3438
# Don't report about shadowed variables
3539
check-shadowing: false

autopilot/agent.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ func (a *Agent) openChans(availableFunds btcutil.Amount, numChans uint32,
629629
nodes[nID] = struct{}{}
630630
return nil
631631
}); err != nil {
632-
return fmt.Errorf("unable to get graph nodes: %v", err)
632+
return fmt.Errorf("unable to get graph nodes: %w", err)
633633
}
634634

635635
// Use the heuristic to calculate a score for each node in the
@@ -639,7 +639,7 @@ func (a *Agent) openChans(availableFunds btcutil.Amount, numChans uint32,
639639
a.cfg.Graph, totalChans, chanSize, nodes,
640640
)
641641
if err != nil {
642-
return fmt.Errorf("unable to calculate node scores : %v", err)
642+
return fmt.Errorf("unable to calculate node scores : %w", err)
643643
}
644644

645645
log.Debugf("Got scores for %d nodes", len(scores))

brontide/noise_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func TestWriteMessageChunking(t *testing.T) {
274274

275275
bytesWritten, err := localConn.Write(largeMessage)
276276
if err != nil {
277-
errCh <- fmt.Errorf("unable to write message: %v", err)
277+
errCh <- fmt.Errorf("unable to write message: %w", err)
278278
return
279279
}
280280

build/logrotator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ func (r *RotatingLogWriter) InitLogRotator(logFile string, maxLogFileSize int,
6464
logDir, _ := filepath.Split(logFile)
6565
err := os.MkdirAll(logDir, 0700)
6666
if err != nil {
67-
return fmt.Errorf("failed to create log directory: %v", err)
67+
return fmt.Errorf("failed to create log directory: %w", err)
6868
}
6969
r.logRotator, err = rotator.New(
7070
logFile, int64(maxLogFileSize*1024), false, maxLogFiles,
7171
)
7272
if err != nil {
73-
return fmt.Errorf("failed to create file rotator: %v", err)
73+
return fmt.Errorf("failed to create file rotator: %w", err)
7474
}
7575

7676
// Run rotator as a goroutine now but make sure we catch any errors

chainntnfs/bitcoindnotify/bitcoind.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ func (b *BitcoindNotifier) handleBlockConnected(block chainntnfs.BlockEpoch) err
636636
// clients.
637637
rawBlock, err := b.GetBlock(block.Hash)
638638
if err != nil {
639-
return fmt.Errorf("unable to get block: %v", err)
639+
return fmt.Errorf("unable to get block: %w", err)
640640
}
641641
utilBlock := btcutil.NewBlock(rawBlock)
642642

@@ -645,7 +645,7 @@ func (b *BitcoindNotifier) handleBlockConnected(block chainntnfs.BlockEpoch) err
645645
// us.
646646
err = b.txNotifier.ConnectTip(utilBlock, uint32(block.Height))
647647
if err != nil {
648-
return fmt.Errorf("unable to connect tip: %v", err)
648+
return fmt.Errorf("unable to connect tip: %w", err)
649649
}
650650

651651
chainntnfs.Log.Infof("New block: height=%v, sha=%v", block.Height,
@@ -719,7 +719,8 @@ func (b *BitcoindNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
719719
pkScript, b.chainParams,
720720
)
721721
if err != nil {
722-
return nil, fmt.Errorf("unable to parse script: %v", err)
722+
return nil, fmt.Errorf("unable to parse script: %w",
723+
err)
723724
}
724725
if err := b.chainConn.NotifyReceived(addrs); err != nil {
725726
return nil, err

chainntnfs/btcdnotify/btcd.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ func (b *BtcdNotifier) handleBlockConnected(epoch chainntnfs.BlockEpoch) error {
692692
// clients.
693693
rawBlock, err := b.GetBlock(epoch.Hash)
694694
if err != nil {
695-
return fmt.Errorf("unable to get block: %v", err)
695+
return fmt.Errorf("unable to get block: %w", err)
696696
}
697697
newBlock := &filteredBlock{
698698
hash: *epoch.Hash,
@@ -706,7 +706,7 @@ func (b *BtcdNotifier) handleBlockConnected(epoch chainntnfs.BlockEpoch) error {
706706
// us.
707707
err = b.txNotifier.ConnectTip(newBlock.block, newBlock.height)
708708
if err != nil {
709-
return fmt.Errorf("unable to connect tip: %v", err)
709+
return fmt.Errorf("unable to connect tip: %w", err)
710710
}
711711

712712
chainntnfs.Log.Infof("New block: height=%v, sha=%v", epoch.Height,
@@ -785,7 +785,8 @@ func (b *BtcdNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
785785
pkScript, b.chainParams,
786786
)
787787
if err != nil {
788-
return nil, fmt.Errorf("unable to parse script: %v", err)
788+
return nil, fmt.Errorf("unable to parse script: %w",
789+
err)
789790
}
790791
if err := b.chainConn.NotifyReceived(addrs); err != nil {
791792
return nil, err
@@ -823,7 +824,8 @@ func (b *BtcdNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
823824
pkScript, b.chainParams,
824825
)
825826
if err != nil {
826-
return nil, fmt.Errorf("unable to parse address: %v", err)
827+
return nil, fmt.Errorf("unable to parse address: %w",
828+
err)
827829
}
828830

829831
asyncResult := b.chainConn.RescanAsync(startHash, addrs, nil)

chainntnfs/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ func GetClientMissedBlocks(chainConn ChainConn, clientBestBlock *BlockEpoch,
541541
chainConn, startingHeight+1, notifierBestHeight+1,
542542
)
543543
if err != nil {
544-
return nil, fmt.Errorf("unable to get missed blocks: %v", err)
544+
return nil, fmt.Errorf("unable to get missed blocks: %w", err)
545545
}
546546

547547
return missedBlocks, nil

chainntnfs/neutrinonotify/neutrino.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,8 @@ func (n *NeutrinoNotifier) historicalConfDetails(confRequest chainntnfs.ConfRequ
609609
key := builder.DeriveKey(blockHash)
610610
match, err := regFilter.Match(key, confRequest.PkScript.Script())
611611
if err != nil {
612-
return nil, fmt.Errorf("unable to query filter: %v", err)
612+
return nil, fmt.Errorf("unable to query filter: %w",
613+
err)
613614
}
614615

615616
// If there's no match, then we can continue forward to the
@@ -623,7 +624,8 @@ func (n *NeutrinoNotifier) historicalConfDetails(confRequest chainntnfs.ConfRequ
623624
// to send the proper response.
624625
block, err := n.GetBlock(*blockHash)
625626
if err != nil {
626-
return nil, fmt.Errorf("unable to get block from network: %v", err)
627+
return nil, fmt.Errorf("unable to get block from "+
628+
"network: %w", err)
627629
}
628630

629631
// For every transaction in the block, check which one matches
@@ -663,11 +665,11 @@ func (n *NeutrinoNotifier) handleBlockConnected(newBlock *filteredBlock) error {
663665
// result in the items we care about being dispatched.
664666
rawBlock, err := n.GetBlock(newBlock.hash)
665667
if err != nil {
666-
return fmt.Errorf("unable to get full block: %v", err)
668+
return fmt.Errorf("unable to get full block: %w", err)
667669
}
668670
err = n.txNotifier.ConnectTip(rawBlock, newBlock.height)
669671
if err != nil {
670-
return fmt.Errorf("unable to connect tip: %v", err)
672+
return fmt.Errorf("unable to connect tip: %w", err)
671673
}
672674

673675
chainntnfs.Log.Infof("New block: height=%v, sha=%v", newBlock.height,
@@ -692,7 +694,7 @@ func (n *NeutrinoNotifier) handleBlockConnected(newBlock *filteredBlock) error {
692694
func (n *NeutrinoNotifier) getFilteredBlock(epoch chainntnfs.BlockEpoch) (*filteredBlock, error) {
693695
rawBlock, err := n.GetBlock(*epoch.Hash)
694696
if err != nil {
695-
return nil, fmt.Errorf("unable to get block: %v", err)
697+
return nil, fmt.Errorf("unable to get block: %w", err)
696698
}
697699

698700
txns := rawBlock.Transactions()
@@ -800,7 +802,7 @@ func (n *NeutrinoNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
800802
return nil, chainntnfs.ErrChainNotifierShuttingDown
801803
}
802804
if err != nil {
803-
return nil, fmt.Errorf("unable to update filter: %v", err)
805+
return nil, fmt.Errorf("unable to update filter: %w", err)
804806
}
805807

806808
// If the txNotifier didn't return any details to perform a historical
@@ -937,7 +939,7 @@ func (n *NeutrinoNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
937939
params := n.p2pNode.ChainParams()
938940
_, addrs, _, err := txscript.ExtractPkScriptAddrs(pkScript, &params)
939941
if err != nil {
940-
return nil, fmt.Errorf("unable to extract script: %v", err)
942+
return nil, fmt.Errorf("unable to extract script: %w", err)
941943
}
942944

943945
// We'll send the filter update request to the notifier's main event
@@ -962,7 +964,7 @@ func (n *NeutrinoNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
962964
return nil, chainntnfs.ErrChainNotifierShuttingDown
963965
}
964966
if err != nil {
965-
return nil, fmt.Errorf("unable to update filter: %v", err)
967+
return nil, fmt.Errorf("unable to update filter: %w", err)
966968
}
967969

968970
// If a historical rescan was not requested by the txNotifier, then we

chainntnfs/test_utils.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ func randPubKeyHashScript() ([]byte, *btcec.PrivateKey, error) {
6767
func GetTestTxidAndScript(h *rpctest.Harness) (*chainhash.Hash, []byte, error) {
6868
pkScript, _, err := randPubKeyHashScript()
6969
if err != nil {
70-
return nil, nil, fmt.Errorf("unable to generate pkScript: %v", err)
70+
return nil, nil, fmt.Errorf("unable to generate pkScript: %w",
71+
err)
7172
}
7273
output := &wire.TxOut{Value: 2e8, PkScript: pkScript}
7374
txid, err := h.SendOutputs([]*wire.TxOut{output}, 10)

chanbackup/backup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func FetchBackupForChan(chanPoint wire.OutPoint, chanSource LiveChannelSource,
7272
// the source to obtain any extra information that we may need.
7373
staticChanBackup, err := assembleChanBackup(addrSource, targetChan)
7474
if err != nil {
75-
return nil, fmt.Errorf("unable to create chan backup: %v", err)
75+
return nil, fmt.Errorf("unable to create chan backup: %w", err)
7676
}
7777

7878
return staticChanBackup, nil

0 commit comments

Comments
 (0)