multi: fix fmt.Errorf error wrapping
Refactor fmt.Errorf usage to correctly wrap errors instead of using non-wrapping format verbs.
This commit is contained in:
103 files changed
+426
-390
No files matched your search
@@ -636,7 +636,7 @@ func (b *BitcoindNotifier) handleBlockConnected(block chainntnfs.BlockEpoch) err
|
||||
// clients.
|
||||
rawBlock, err := b.GetBlock(block.Hash)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to get block: %v", err)
|
||||
return fmt.Errorf("unable to get block: %w", err)
|
||||
}
|
||||
utilBlock := btcutil.NewBlock(rawBlock)
|
||||
|
||||
@@ -645,7 +645,7 @@ func (b *BitcoindNotifier) handleBlockConnected(block chainntnfs.BlockEpoch) err
|
||||
// us.
|
||||
err = b.txNotifier.ConnectTip(utilBlock, uint32(block.Height))
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to connect tip: %v", err)
|
||||
return fmt.Errorf("unable to connect tip: %w", err)
|
||||
}
|
||||
|
||||
chainntnfs.Log.Infof("New block: height=%v, sha=%v", block.Height,
|
||||
@@ -719,7 +719,8 @@ func (b *BitcoindNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
|
||||
pkScript, b.chainParams,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse script: %v", err)
|
||||
return nil, fmt.Errorf("unable to parse script: %w",
|
||||
err)
|
||||
}
|
||||
if err := b.chainConn.NotifyReceived(addrs); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -692,7 +692,7 @@ func (b *BtcdNotifier) handleBlockConnected(epoch chainntnfs.BlockEpoch) error {
|
||||
// clients.
|
||||
rawBlock, err := b.GetBlock(epoch.Hash)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to get block: %v", err)
|
||||
return fmt.Errorf("unable to get block: %w", err)
|
||||
}
|
||||
newBlock := &filteredBlock{
|
||||
hash: *epoch.Hash,
|
||||
@@ -706,7 +706,7 @@ func (b *BtcdNotifier) handleBlockConnected(epoch chainntnfs.BlockEpoch) error {
|
||||
// us.
|
||||
err = b.txNotifier.ConnectTip(newBlock.block, newBlock.height)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to connect tip: %v", err)
|
||||
return fmt.Errorf("unable to connect tip: %w", err)
|
||||
}
|
||||
|
||||
chainntnfs.Log.Infof("New block: height=%v, sha=%v", epoch.Height,
|
||||
@@ -785,7 +785,8 @@ func (b *BtcdNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
|
||||
pkScript, b.chainParams,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse script: %v", err)
|
||||
return nil, fmt.Errorf("unable to parse script: %w",
|
||||
err)
|
||||
}
|
||||
if err := b.chainConn.NotifyReceived(addrs); err != nil {
|
||||
return nil, err
|
||||
@@ -823,7 +824,8 @@ func (b *BtcdNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
|
||||
pkScript, b.chainParams,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse address: %v", err)
|
||||
return nil, fmt.Errorf("unable to parse address: %w",
|
||||
err)
|
||||
}
|
||||
|
||||
asyncResult := b.chainConn.RescanAsync(startHash, addrs, nil)
|
||||
|
||||
@@ -541,7 +541,7 @@ func GetClientMissedBlocks(chainConn ChainConn, clientBestBlock *BlockEpoch,
|
||||
chainConn, startingHeight+1, notifierBestHeight+1,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get missed blocks: %v", err)
|
||||
return nil, fmt.Errorf("unable to get missed blocks: %w", err)
|
||||
}
|
||||
|
||||
return missedBlocks, nil
|
||||
|
||||
@@ -609,7 +609,8 @@ func (n *NeutrinoNotifier) historicalConfDetails(confRequest chainntnfs.ConfRequ
|
||||
key := builder.DeriveKey(blockHash)
|
||||
match, err := regFilter.Match(key, confRequest.PkScript.Script())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to query filter: %v", err)
|
||||
return nil, fmt.Errorf("unable to query filter: %w",
|
||||
err)
|
||||
}
|
||||
|
||||
// If there's no match, then we can continue forward to the
|
||||
@@ -623,7 +624,8 @@ func (n *NeutrinoNotifier) historicalConfDetails(confRequest chainntnfs.ConfRequ
|
||||
// to send the proper response.
|
||||
block, err := n.GetBlock(*blockHash)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get block from network: %v", err)
|
||||
return nil, fmt.Errorf("unable to get block from "+
|
||||
"network: %w", err)
|
||||
}
|
||||
|
||||
// For every transaction in the block, check which one matches
|
||||
@@ -663,11 +665,11 @@ func (n *NeutrinoNotifier) handleBlockConnected(newBlock *filteredBlock) error {
|
||||
// result in the items we care about being dispatched.
|
||||
rawBlock, err := n.GetBlock(newBlock.hash)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to get full block: %v", err)
|
||||
return fmt.Errorf("unable to get full block: %w", err)
|
||||
}
|
||||
err = n.txNotifier.ConnectTip(rawBlock, newBlock.height)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to connect tip: %v", err)
|
||||
return fmt.Errorf("unable to connect tip: %w", err)
|
||||
}
|
||||
|
||||
chainntnfs.Log.Infof("New block: height=%v, sha=%v", newBlock.height,
|
||||
@@ -692,7 +694,7 @@ func (n *NeutrinoNotifier) handleBlockConnected(newBlock *filteredBlock) error {
|
||||
func (n *NeutrinoNotifier) getFilteredBlock(epoch chainntnfs.BlockEpoch) (*filteredBlock, error) {
|
||||
rawBlock, err := n.GetBlock(*epoch.Hash)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get block: %v", err)
|
||||
return nil, fmt.Errorf("unable to get block: %w", err)
|
||||
}
|
||||
|
||||
txns := rawBlock.Transactions()
|
||||
@@ -800,7 +802,7 @@ func (n *NeutrinoNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
|
||||
return nil, chainntnfs.ErrChainNotifierShuttingDown
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to update filter: %v", err)
|
||||
return nil, fmt.Errorf("unable to update filter: %w", err)
|
||||
}
|
||||
|
||||
// If the txNotifier didn't return any details to perform a historical
|
||||
@@ -937,7 +939,7 @@ func (n *NeutrinoNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
|
||||
params := n.p2pNode.ChainParams()
|
||||
_, addrs, _, err := txscript.ExtractPkScriptAddrs(pkScript, ¶ms)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to extract script: %v", err)
|
||||
return nil, fmt.Errorf("unable to extract script: %w", err)
|
||||
}
|
||||
|
||||
// We'll send the filter update request to the notifier's main event
|
||||
@@ -962,7 +964,7 @@ func (n *NeutrinoNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
|
||||
return nil, chainntnfs.ErrChainNotifierShuttingDown
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to update filter: %v", err)
|
||||
return nil, fmt.Errorf("unable to update filter: %w", err)
|
||||
}
|
||||
|
||||
// If a historical rescan was not requested by the txNotifier, then we
|
||||
|
||||
@@ -67,7 +67,8 @@ func randPubKeyHashScript() ([]byte, *btcec.PrivateKey, error) {
|
||||
func GetTestTxidAndScript(h *rpctest.Harness) (*chainhash.Hash, []byte, error) {
|
||||
pkScript, _, err := randPubKeyHashScript()
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("unable to generate pkScript: %v", err)
|
||||
return nil, nil, fmt.Errorf("unable to generate pkScript: %w",
|
||||
err)
|
||||
}
|
||||
output := &wire.TxOut{Value: 2e8, PkScript: pkScript}
|
||||
txid, err := h.SendOutputs([]*wire.TxOut{output}, 10)
|
||||
|
||||
Reference in new issue
Block a user