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
@@ -246,7 +246,7 @@ func serializeTxWitness(txWitness wire.TxWitness) ([]byte, error) {
|
||||
var witnessBytes bytes.Buffer
|
||||
err := psbt.WriteTxWitness(&witnessBytes, txWitness)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error serializing witness: %v", err)
|
||||
return nil, fmt.Errorf("error serializing witness: %w", err)
|
||||
}
|
||||
|
||||
return witnessBytes.Bytes(), nil
|
||||
|
||||
@@ -1077,7 +1077,7 @@ func ParseUpfrontShutdownAddress(address string,
|
||||
address, params,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid address: %v", err)
|
||||
return nil, fmt.Errorf("invalid address: %w", err)
|
||||
}
|
||||
|
||||
if !addr.IsForNet(params) {
|
||||
|
||||
@@ -227,7 +227,7 @@ func (i *PsbtIntent) Verify(packet *psbt.Packet, skipFinalize bool) error {
|
||||
// Try to locate the channel funding multisig output.
|
||||
_, expectedOutput, err := i.FundingOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("funding output cannot be created: %v", err)
|
||||
return fmt.Errorf("funding output cannot be created: %w", err)
|
||||
}
|
||||
outputFound := false
|
||||
outputSum := int64(0)
|
||||
@@ -250,7 +250,7 @@ func (i *PsbtIntent) Verify(packet *psbt.Packet, skipFinalize bool) error {
|
||||
}
|
||||
sum, err := psbt.SumUtxoInputValues(packet)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error determining input sum: %v", err)
|
||||
return fmt.Errorf("error determining input sum: %w", err)
|
||||
}
|
||||
if sum <= outputSum {
|
||||
return fmt.Errorf("input amount sum must be larger than " +
|
||||
@@ -304,11 +304,11 @@ func (i *PsbtIntent) Finalize(packet *psbt.Packet) error {
|
||||
// broadcast.
|
||||
err := psbt.MaybeFinalizeAll(packet)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error finalizing PSBT: %v", err)
|
||||
return fmt.Errorf("error finalizing PSBT: %w", err)
|
||||
}
|
||||
rawTx, err := psbt.Extract(packet)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to extract funding TX: %v", err)
|
||||
return fmt.Errorf("unable to extract funding TX: %w", err)
|
||||
}
|
||||
|
||||
return i.FinalizeRawTX(rawTx)
|
||||
@@ -340,13 +340,13 @@ func (i *PsbtIntent) FinalizeRawTX(rawTx *wire.MsgTx) error {
|
||||
rawTx.TxOut, i.PendingPsbt.UnsignedTx.TxOut,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("outputs differ from verified PSBT: %v", err)
|
||||
return fmt.Errorf("outputs differ from verified PSBT: %w", err)
|
||||
}
|
||||
err = psbt.VerifyInputPrevOutpointsEqual(
|
||||
rawTx.TxIn, i.PendingPsbt.UnsignedTx.TxIn,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inputs differ from verified PSBT: %v", err)
|
||||
return fmt.Errorf("inputs differ from verified PSBT: %w", err)
|
||||
}
|
||||
|
||||
// We also check that we have a signed TX. This is only necessary if the
|
||||
@@ -354,7 +354,7 @@ func (i *PsbtIntent) FinalizeRawTX(rawTx *wire.MsgTx) error {
|
||||
// extracting the TX from a PSBT.
|
||||
err = verifyInputsSigned(rawTx.TxIn)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inputs not signed: %v", err)
|
||||
return fmt.Errorf("inputs not signed: %w", err)
|
||||
}
|
||||
|
||||
// As far as we can tell, this TX is ok to be used as a funding
|
||||
@@ -383,7 +383,7 @@ func (i *PsbtIntent) CompileFundingTx() (*wire.MsgTx, error) {
|
||||
// Identify our funding outpoint now that we know everything's ready.
|
||||
_, txOut, err := i.FundingOutput()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get funding output: %v", err)
|
||||
return nil, fmt.Errorf("cannot get funding output: %w", err)
|
||||
}
|
||||
ok, idx := input.FindScriptOutputIndex(i.FinalTX, txOut.PkScript)
|
||||
if !ok {
|
||||
|
||||
@@ -6796,10 +6796,10 @@ func compareLogs(a, b *updateLog) error {
|
||||
}
|
||||
|
||||
if err := compareIndexes(a.updateIndex, b.updateIndex); err != nil {
|
||||
return fmt.Errorf("update indexes don't match: %v", err)
|
||||
return fmt.Errorf("update indexes don't match: %w", err)
|
||||
}
|
||||
if err := compareIndexes(a.htlcIndex, b.htlcIndex); err != nil {
|
||||
return fmt.Errorf("htlc indexes don't match: %v", err)
|
||||
return fmt.Errorf("htlc indexes don't match: %w", err)
|
||||
}
|
||||
|
||||
if a.Len() != b.Len() {
|
||||
|
||||
@@ -156,7 +156,7 @@ func (r *RPCKeyRing) SendOutputs(outputs []*wire.TxOut,
|
||||
&txIn.PreviousOutPoint,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error looking up utxo: %v", err)
|
||||
return nil, fmt.Errorf("error looking up utxo: %w", err)
|
||||
}
|
||||
|
||||
if txscript.IsPayToTaproot(info.PkScript) {
|
||||
@@ -201,7 +201,7 @@ func (r *RPCKeyRing) SignPsbt(packet *psbt.Packet) ([]uint32, error) {
|
||||
|
||||
var buf bytes.Buffer
|
||||
if err := packet.Serialize(&buf); err != nil {
|
||||
return nil, fmt.Errorf("error serializing PSBT: %v", err)
|
||||
return nil, fmt.Errorf("error serializing PSBT: %w", err)
|
||||
}
|
||||
|
||||
resp, err := r.walletClient.SignPsbt(ctxt, &walletrpc.SignPsbtRequest{
|
||||
@@ -217,7 +217,7 @@ func (r *RPCKeyRing) SignPsbt(packet *psbt.Packet) ([]uint32, error) {
|
||||
bytes.NewReader(resp.SignedPsbt), false,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing signed PSBT: %v", err)
|
||||
return nil, fmt.Errorf("error parsing signed PSBT: %w", err)
|
||||
}
|
||||
|
||||
// The caller expects the packet to be modified instead of a new
|
||||
@@ -349,7 +349,7 @@ func (r *RPCKeyRing) FinalizePsbt(packet *psbt.Packet, _ string) error {
|
||||
var witnessBytes bytes.Buffer
|
||||
err = psbt.WriteTxWitness(&witnessBytes, script.Witness)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error serializing witness: %v", err)
|
||||
return fmt.Errorf("error serializing witness: %w", err)
|
||||
}
|
||||
packet.Inputs[idx].FinalScriptWitness = witnessBytes.Bytes()
|
||||
packet.Inputs[idx].FinalScriptSig = script.SigScript
|
||||
@@ -359,7 +359,7 @@ func (r *RPCKeyRing) FinalizePsbt(packet *psbt.Packet, _ string) error {
|
||||
// broadcast.
|
||||
err = psbt.MaybeFinalizeAll(packet)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error finalizing PSBT: %v", err)
|
||||
return fmt.Errorf("error finalizing PSBT: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -732,7 +732,7 @@ func (r *RPCKeyRing) MuSig2CreateSession(bipVersion input.MuSig2Version,
|
||||
|
||||
info.CombinedKey, err = schnorr.ParsePubKey(resp.CombinedKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing combined key: %v", err)
|
||||
return nil, fmt.Errorf("error parsing combined key: %w", err)
|
||||
}
|
||||
|
||||
if tweaks.HasTaprootTweak() {
|
||||
@@ -891,7 +891,7 @@ func (r *RPCKeyRing) remoteSign(tx *wire.MsgTx, signDesc *input.SignDescriptor,
|
||||
|
||||
packet, err := packetFromTx(tx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error converting TX into PSBT: %v", err)
|
||||
return nil, fmt.Errorf("error converting TX into PSBT: %w", err)
|
||||
}
|
||||
|
||||
// We need to add witness information for all inputs! Otherwise, we'll
|
||||
@@ -1157,7 +1157,7 @@ func (r *RPCKeyRing) remoteSign(tx *wire.MsgTx, signDesc *input.SignDescriptor,
|
||||
|
||||
var buf bytes.Buffer
|
||||
if err := packet.Serialize(&buf); err != nil {
|
||||
return nil, fmt.Errorf("error serializing PSBT: %v", err)
|
||||
return nil, fmt.Errorf("error serializing PSBT: %w", err)
|
||||
}
|
||||
|
||||
resp, err := r.walletClient.SignPsbt(
|
||||
@@ -1173,7 +1173,7 @@ func (r *RPCKeyRing) remoteSign(tx *wire.MsgTx, signDesc *input.SignDescriptor,
|
||||
bytes.NewReader(resp.SignedPsbt), false,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing signed PSBT: %v", err)
|
||||
return nil, fmt.Errorf("error parsing signed PSBT: %w", err)
|
||||
}
|
||||
|
||||
// We expect a signature in the input now.
|
||||
@@ -1278,12 +1278,12 @@ func connectRPC(hostPort, tlsCertPath, macaroonPath string,
|
||||
}
|
||||
mac := &macaroon.Macaroon{}
|
||||
if err := mac.UnmarshalBinary(macBytes); err != nil {
|
||||
return nil, fmt.Errorf("error decoding macaroon: %v", err)
|
||||
return nil, fmt.Errorf("error decoding macaroon: %w", err)
|
||||
}
|
||||
|
||||
macCred, err := macaroons.NewMacaroonCredential(mac)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating creds: %v", err)
|
||||
return nil, fmt.Errorf("error creating creds: %w", err)
|
||||
}
|
||||
|
||||
opts := []grpc.DialOption{
|
||||
|
||||
@@ -264,7 +264,7 @@ func loadTestCredits(miner *rpctest.Harness, w *lnwallet.LightningWallet,
|
||||
// give us btcPerOutput with each output.
|
||||
satoshiPerOutput, err := btcutil.NewAmount(btcPerOutput)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create amt: %v", err)
|
||||
return fmt.Errorf("unable to create amt: %w", err)
|
||||
}
|
||||
expectedBalance, err := w.ConfirmedBalance(1, lnwallet.DefaultAccountName)
|
||||
if err != nil {
|
||||
@@ -1511,11 +1511,11 @@ func scriptFromKey(pubkey *btcec.PublicKey) ([]byte, error) {
|
||||
pubkeyHash, &chaincfg.RegressionNetParams,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to create addr: %v", err)
|
||||
return nil, fmt.Errorf("unable to create addr: %w", err)
|
||||
}
|
||||
keyScript, err := txscript.PayToAddrScript(keyAddr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to generate script: %v", err)
|
||||
return nil, fmt.Errorf("unable to generate script: %w", err)
|
||||
}
|
||||
|
||||
return keyScript, nil
|
||||
@@ -1526,17 +1526,17 @@ func mineAndAssert(r *rpctest.Harness, tx *wire.MsgTx) error {
|
||||
txid := tx.TxHash()
|
||||
err := waitForMempoolTx(r, &txid)
|
||||
if err != nil {
|
||||
return fmt.Errorf("tx not relayed to miner: %v", err)
|
||||
return fmt.Errorf("tx not relayed to miner: %w", err)
|
||||
}
|
||||
|
||||
blockHashes, err := r.Client.Generate(1)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to generate block: %v", err)
|
||||
return fmt.Errorf("unable to generate block: %w", err)
|
||||
}
|
||||
|
||||
block, err := r.Client.GetBlock(blockHashes[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to find block: %v", err)
|
||||
return fmt.Errorf("unable to find block: %w", err)
|
||||
}
|
||||
|
||||
if len(block.Transactions) != 2 {
|
||||
@@ -1564,7 +1564,7 @@ func txFromOutput(tx *wire.MsgTx, signer input.Signer, fromPubKey,
|
||||
// Generate the script we want to spend from.
|
||||
keyScript, err := scriptFromKey(fromPubKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to generate script: %v", err)
|
||||
return nil, fmt.Errorf("unable to generate script: %w", err)
|
||||
}
|
||||
|
||||
// We assume the output was paid to the keyScript made earlier.
|
||||
@@ -1599,7 +1599,7 @@ func txFromOutput(tx *wire.MsgTx, signer input.Signer, fromPubKey,
|
||||
// Create a script to pay to.
|
||||
payToScript, err := scriptFromKey(payToPubKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to generate script: %v", err)
|
||||
return nil, fmt.Errorf("unable to generate script: %w", err)
|
||||
}
|
||||
tx1.AddTxOut(&wire.TxOut{
|
||||
Value: outputValue - int64(txFee),
|
||||
@@ -1623,7 +1623,7 @@ func txFromOutput(tx *wire.MsgTx, signer input.Signer, fromPubKey,
|
||||
// manually create a valid witness stack we'll use for signing.
|
||||
spendSig, err := signer.SignOutputRaw(tx1, signDesc)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to generate signature: %v", err)
|
||||
return nil, fmt.Errorf("unable to generate signature: %w", err)
|
||||
}
|
||||
witness := make([][]byte, 2)
|
||||
witness[0] = append(spendSig.Serialize(), byte(txscript.SigHashAll))
|
||||
@@ -1640,10 +1640,10 @@ func txFromOutput(tx *wire.MsgTx, signer input.Signer, fromPubKey,
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to create engine: %v", err)
|
||||
return nil, fmt.Errorf("unable to create engine: %w", err)
|
||||
}
|
||||
if err := vm.Execute(); err != nil {
|
||||
return nil, fmt.Errorf("spend is invalid: %v", err)
|
||||
return nil, fmt.Errorf("spend is invalid: %w", err)
|
||||
}
|
||||
|
||||
return tx1, nil
|
||||
|
||||
+7
-5
@@ -721,7 +721,7 @@ func (l *LightningWallet) PsbtFundingVerify(pendingChanID [32]byte,
|
||||
|
||||
err := psbtIntent.Verify(packet, skipFinalize)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error verifying PSBT: %v", err)
|
||||
return fmt.Errorf("error verifying PSBT: %w", err)
|
||||
}
|
||||
|
||||
// Get the channel reservation for that corresponds to this pending
|
||||
@@ -773,13 +773,13 @@ func (l *LightningWallet) PsbtFundingFinalize(pid [32]byte, packet *psbt.Packet,
|
||||
case packet != nil && rawTx == nil:
|
||||
err := psbtIntent.Finalize(packet)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error finalizing PSBT: %v", err)
|
||||
return fmt.Errorf("error finalizing PSBT: %w", err)
|
||||
}
|
||||
|
||||
case rawTx != nil && packet == nil:
|
||||
err := psbtIntent.FinalizeRawTX(rawTx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error finalizing raw TX: %v", err)
|
||||
return fmt.Errorf("error finalizing raw TX: %w", err)
|
||||
}
|
||||
|
||||
default:
|
||||
@@ -1554,7 +1554,8 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) {
|
||||
case *chanfunding.ShimIntent:
|
||||
chanPoint, err = fundingIntent.ChanPoint()
|
||||
if err != nil {
|
||||
req.err <- fmt.Errorf("unable to obtain chan point: %v", err)
|
||||
req.err <- fmt.Errorf("unable to obtain chan point: %w",
|
||||
err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1996,7 +1997,8 @@ func (l *LightningWallet) verifyFundingInputs(fundingTx *wire.MsgTx,
|
||||
txin.SignatureScript, txin.Witness,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create script: %v", err)
|
||||
return fmt.Errorf("cannot create script: %w",
|
||||
err)
|
||||
}
|
||||
output, err := l.Cfg.ChainIO.GetUtxo(
|
||||
&txin.PreviousOutPoint,
|
||||
|
||||
Reference in new issue
Block a user