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:
ffranr committed 2024-02-27 11:13:40 +00:00
1 parent 581c16d72f
commit cd566eb097
103 files changed
+426 -390

No files matched your search

+2 -2
View File
@@ -181,12 +181,12 @@ func parseOutPoint(s string) (*wire.OutPoint, error) {
index, err := strconv.ParseInt(split[1], 10, 32)
if err != nil {
return nil, fmt.Errorf("unable to decode output index: %v", err)
return nil, fmt.Errorf("unable to decode output index: %w", err)
}
txid, err := chainhash.NewHashFromStr(split[0])
if err != nil {
return nil, fmt.Errorf("unable to parse hex string: %v", err)
return nil, fmt.Errorf("unable to parse hex string: %w", err)
}
return &wire.OutPoint{
+1 -1
View File
@@ -198,7 +198,7 @@ func (s *Server) Status(ctx context.Context,
bestBlock, err := s.cfg.NeutrinoCS.BestBlock()
if err != nil {
return nil, fmt.Errorf("could not get best block: %v", err)
return nil, fmt.Errorf("could not get best block: %w", err)
}
peers := s.cfg.NeutrinoCS.Peers()
+2 -2
View File
@@ -335,7 +335,7 @@ func (s *Server) UpdateNodeAnnouncement(_ context.Context,
if req.Color != "" {
color, err := lncfg.ParseHexColor(req.Color)
if err != nil {
return nil, fmt.Errorf("unable to parse color: %v", err)
return nil, fmt.Errorf("unable to parse color: %w", err)
}
if color != currentNodeAnn.RGBColor {
@@ -355,7 +355,7 @@ func (s *Server) UpdateNodeAnnouncement(_ context.Context,
if req.Alias != "" {
alias, err := lnwire.NewNodeAlias(req.Alias)
if err != nil {
return nil, fmt.Errorf("invalid alias value: %v", err)
return nil, fmt.Errorf("invalid alias value: %w", err)
}
if alias != currentNodeAnn.Alias {
resp.Ops = append(resp.Ops, &lnrpc.Op{
+24 -24
View File
@@ -293,7 +293,7 @@ func (s *Server) SignOutputRaw(_ context.Context, in *SignReq) (*SignResp,
)
txReader := bytes.NewReader(in.RawTxBytes)
if err := txToSign.Deserialize(txReader); err != nil {
return nil, fmt.Errorf("unable to decode tx: %v", err)
return nil, fmt.Errorf("unable to decode tx: %w", err)
}
var (
@@ -520,7 +520,7 @@ func (s *Server) ComputeInputScript(ctx context.Context,
var txToSign wire.MsgTx
txReader := bytes.NewReader(in.RawTxBytes)
if err := txToSign.Deserialize(txReader); err != nil {
return nil, fmt.Errorf("unable to decode tx: %v", err)
return nil, fmt.Errorf("unable to decode tx: %w", err)
}
var (
@@ -636,7 +636,7 @@ func (s *Server) SignMessage(_ context.Context,
in.SchnorrSigTapTweak, in.Tag,
)
if err != nil {
return nil, fmt.Errorf("can't sign the hash: %v", err)
return nil, fmt.Errorf("can't sign the hash: %w", err)
}
sigParsed, err := schnorr.ParseSignature(sig.Serialize())
@@ -659,7 +659,7 @@ func (s *Server) SignMessage(_ context.Context,
keyLocator, in.Msg, in.DoubleHash,
)
if err != nil {
return nil, fmt.Errorf("can't sign the hash: %v", err)
return nil, fmt.Errorf("can't sign the hash: %w", err)
}
return &SignMessageResp{
@@ -673,11 +673,11 @@ func (s *Server) SignMessage(_ context.Context,
keyLocator, in.Msg, in.DoubleHash,
)
if err != nil {
return nil, fmt.Errorf("can't sign the hash: %v", err)
return nil, fmt.Errorf("can't sign the hash: %w", err)
}
wireSig, err := lnwire.NewSigFromSignature(sig)
if err != nil {
return nil, fmt.Errorf("can't convert to wire format: %v", err)
return nil, fmt.Errorf("can't convert to wire format: %w", err)
}
return &SignMessageResp{
Signature: wireSig.ToSignatureBytes(),
@@ -736,13 +736,13 @@ func (s *Server) VerifyMessage(_ context.Context,
pubkey, err := btcec.ParsePubKey(in.Pubkey)
if err != nil {
return nil, fmt.Errorf("unable to parse pubkey: %v", err)
return nil, fmt.Errorf("unable to parse pubkey: %w", err)
}
// The signature must be fixed-size LN wire format encoded.
wireSig, err := lnwire.NewSigFromECDSARawSignature(in.Signature)
if err != nil {
return nil, fmt.Errorf("failed to decode signature: %v", err)
return nil, fmt.Errorf("failed to decode signature: %w", err)
}
sig, err := wireSig.ToSignature()
if err != nil {
@@ -772,7 +772,7 @@ func (s *Server) DeriveSharedKey(_ context.Context, in *SharedKeyRequest) (
// Check that EphemeralPubkey is valid.
ephemeralPubkey, err := parseRawKeyBytes(in.EphemeralPubkey)
if err != nil {
return nil, fmt.Errorf("error in ephemeral pubkey: %v", err)
return nil, fmt.Errorf("error in ephemeral pubkey: %w", err)
}
if ephemeralPubkey == nil {
return nil, fmt.Errorf("must provide ephemeral pubkey")
@@ -820,7 +820,7 @@ func (s *Server) DeriveSharedKey(_ context.Context, in *SharedKeyRequest) (
// *btcec.PublicKey is returned instead.
pk, err := parseRawKeyBytes(rawKeyBytes)
if err != nil {
return nil, fmt.Errorf("error in raw pubkey: %v", err)
return nil, fmt.Errorf("error in raw pubkey: %w", err)
}
// Create a key descriptor. When the KeyIndex is not specified, it uses
@@ -838,7 +838,7 @@ func (s *Server) DeriveSharedKey(_ context.Context, in *SharedKeyRequest) (
// compressed shared point.
sharedKeyHash, err := s.cfg.KeyRing.ECDH(keyDescriptor, ephemeralPubkey)
if err != nil {
err := fmt.Errorf("unable to derive shared key: %v", err)
err := fmt.Errorf("unable to derive shared key: %w", err)
log.Error(err)
return nil, err
}
@@ -883,7 +883,7 @@ func (s *Server) MuSig2CombineKeys(_ context.Context,
version, allSignerPubKeys, true, tweaks,
)
if err != nil {
return nil, fmt.Errorf("error combining keys: %v", err)
return nil, fmt.Errorf("error combining keys: %w", err)
}
var internalKeyBytes []byte
@@ -1008,7 +1008,7 @@ func (s *Server) MuSig2CreateSession(_ context.Context,
in.OtherSignerPublicNonces, true,
)
if err != nil {
return nil, fmt.Errorf("error parsing other nonces: %v", err)
return nil, fmt.Errorf("error parsing other nonces: %w", err)
}
// Are there any tweaks to apply to the combined public key?
@@ -1024,7 +1024,7 @@ func (s *Server) MuSig2CreateSession(_ context.Context,
localNonces,
)
if err != nil {
return nil, fmt.Errorf("error registering session: %v", err)
return nil, fmt.Errorf("error registering session: %w", err)
}
var internalKeyBytes []byte
@@ -1054,7 +1054,7 @@ func (s *Server) MuSig2RegisterNonces(_ context.Context,
// Check session ID length.
sessionID, err := parseMuSig2SessionID(in.SessionId)
if err != nil {
return nil, fmt.Errorf("error parsing session ID: %v", err)
return nil, fmt.Errorf("error parsing session ID: %w", err)
}
// Parse the other signing participants' nonces. We can't validate the
@@ -1067,7 +1067,7 @@ func (s *Server) MuSig2RegisterNonces(_ context.Context,
in.OtherSignerPublicNonces, false,
)
if err != nil {
return nil, fmt.Errorf("error parsing other nonces: %v", err)
return nil, fmt.Errorf("error parsing other nonces: %w", err)
}
// Register the nonces now.
@@ -1075,7 +1075,7 @@ func (s *Server) MuSig2RegisterNonces(_ context.Context,
sessionID, otherSignerNonces,
)
if err != nil {
return nil, fmt.Errorf("error registering nonces: %v", err)
return nil, fmt.Errorf("error registering nonces: %w", err)
}
return &MuSig2RegisterNoncesResponse{HaveAllNonces: haveAllNonces}, nil
@@ -1093,7 +1093,7 @@ func (s *Server) MuSig2Sign(_ context.Context,
// Check session ID length.
sessionID, err := parseMuSig2SessionID(in.SessionId)
if err != nil {
return nil, fmt.Errorf("error parsing session ID: %v", err)
return nil, fmt.Errorf("error parsing session ID: %w", err)
}
// Schnorr signatures only work reliably if the message is 32 bytes.
@@ -1107,12 +1107,12 @@ func (s *Server) MuSig2Sign(_ context.Context,
// Create our own partial signature with the local signing key.
partialSig, err := s.cfg.Signer.MuSig2Sign(sessionID, msg, in.Cleanup)
if err != nil {
return nil, fmt.Errorf("error signing: %v", err)
return nil, fmt.Errorf("error signing: %w", err)
}
serializedPartialSig, err := input.SerializePartialSignature(partialSig)
if err != nil {
return nil, fmt.Errorf("error serializing sig: %v", err)
return nil, fmt.Errorf("error serializing sig: %w", err)
}
return &MuSig2SignResponse{
@@ -1129,7 +1129,7 @@ func (s *Server) MuSig2CombineSig(_ context.Context,
// Check session ID length.
sessionID, err := parseMuSig2SessionID(in.SessionId)
if err != nil {
return nil, fmt.Errorf("error parsing session ID: %v", err)
return nil, fmt.Errorf("error parsing session ID: %w", err)
}
// Parse all other signatures. This can be called multiple times, so we
@@ -1149,7 +1149,7 @@ func (s *Server) MuSig2CombineSig(_ context.Context,
sessionID, partialSigs,
)
if err != nil {
return nil, fmt.Errorf("error combining signatures: %v", err)
return nil, fmt.Errorf("error combining signatures: %w", err)
}
resp := &MuSig2CombineSigResponse{
@@ -1170,12 +1170,12 @@ func (s *Server) MuSig2Cleanup(_ context.Context,
// Check session ID length.
sessionID, err := parseMuSig2SessionID(in.SessionId)
if err != nil {
return nil, fmt.Errorf("error parsing session ID: %v", err)
return nil, fmt.Errorf("error parsing session ID: %w", err)
}
err = s.cfg.Signer.MuSig2Cleanup(sessionID)
if err != nil {
return nil, fmt.Errorf("error cleaning up session: %v", err)
return nil, fmt.Errorf("error cleaning up session: %w", err)
}
return &MuSig2CleanupResponse{}, nil
+10 -10
View File
@@ -1434,7 +1434,7 @@ func (w *WalletKit) fundPsbtInternalWallet(account string,
packet, minConfs, feeSatPerKW, account, keyScope,
)
if err != nil {
return fmt.Errorf("wallet couldn't fund PSBT: %v", err)
return fmt.Errorf("wallet couldn't fund PSBT: %w", err)
}
// Now we have obtained a set of coins that can be used to fund
@@ -1865,7 +1865,7 @@ func (w *WalletKit) SignPsbt(_ context.Context, req *SignPsbtRequest) (
if err != nil {
log.Debugf("Error parsing PSBT: %v, raw input: %x", err,
req.FundedPsbt)
return nil, fmt.Errorf("error parsing PSBT: %v", err)
return nil, fmt.Errorf("error parsing PSBT: %w", err)
}
// Before we attempt to sign the packet, ensure that every input either
@@ -1886,14 +1886,14 @@ func (w *WalletKit) SignPsbt(_ context.Context, req *SignPsbtRequest) (
// witness data attached, they will just be skipped.
signedInputs, err := w.cfg.Wallet.SignPsbt(packet)
if err != nil {
return nil, fmt.Errorf("error signing PSBT: %v", err)
return nil, fmt.Errorf("error signing PSBT: %w", err)
}
// Serialize the signed PSBT in both the packet and wire format.
var signedPsbtBytes bytes.Buffer
err = packet.Serialize(&signedPsbtBytes)
if err != nil {
return nil, fmt.Errorf("error serializing PSBT: %v", err)
return nil, fmt.Errorf("error serializing PSBT: %w", err)
}
return &SignPsbtResponse{
@@ -1928,7 +1928,7 @@ func (w *WalletKit) FinalizePsbt(_ context.Context,
bytes.NewReader(req.FundedPsbt), false,
)
if err != nil {
return nil, fmt.Errorf("error parsing PSBT: %v", err)
return nil, fmt.Errorf("error parsing PSBT: %w", err)
}
// The only check done at this level is to validate that the PSBT is
@@ -1942,7 +1942,7 @@ func (w *WalletKit) FinalizePsbt(_ context.Context,
// witness data attached, this will fail.
err = w.cfg.Wallet.FinalizePsbt(packet, account)
if err != nil {
return nil, fmt.Errorf("error finalizing PSBT: %v", err)
return nil, fmt.Errorf("error finalizing PSBT: %w", err)
}
var (
@@ -1953,15 +1953,15 @@ func (w *WalletKit) FinalizePsbt(_ context.Context,
// Serialize the finalized PSBT in both the packet and wire format.
err = packet.Serialize(&finalPsbtBytes)
if err != nil {
return nil, fmt.Errorf("error serializing PSBT: %v", err)
return nil, fmt.Errorf("error serializing PSBT: %w", err)
}
finalTx, err := psbt.Extract(packet)
if err != nil {
return nil, fmt.Errorf("unable to extract final TX: %v", err)
return nil, fmt.Errorf("unable to extract final TX: %w", err)
}
err = finalTx.Serialize(&finalTxBytes)
if err != nil {
return nil, fmt.Errorf("error serializing final TX: %v", err)
return nil, fmt.Errorf("error serializing final TX: %w", err)
}
return &FinalizePsbtResponse{
@@ -2544,7 +2544,7 @@ func (w *WalletKit) ImportTapscript(_ context.Context,
internalKey, err := schnorr.ParsePubKey(req.InternalPublicKey)
if err != nil {
return nil, fmt.Errorf("error parsing internal key: %v", err)
return nil, fmt.Errorf("error parsing internal key: %w", err)
}
var tapscript *waddrmgr.Tapscript