multi: wrap all errors

This commit is contained in:
Oliver Gugger
2024-03-07 13:19:28 +01:00
committed by Andras Banki-Horvath
parent 9a28a4c105
commit 648fb22f63
60 changed files with 138 additions and 133 deletions

View File

@@ -361,7 +361,7 @@ func printMacaroon(ctx *cli.Context) error {
case args.Present():
macBytes, err = hex.DecodeString(args.First())
if err != nil {
return fmt.Errorf("unable to hex decode macaroon: %v",
return fmt.Errorf("unable to hex decode macaroon: %w",
err)
}

View File

@@ -602,7 +602,7 @@ func openChannelPsbt(rpcCtx context.Context, ctx *cli.Context,
// Recv blocks until a message or error arrives.
resp, err := stream.Recv()
if err == io.EOF {
srvErr <- fmt.Errorf("lnd shutting down: %v",
srvErr <- fmt.Errorf("lnd shutting down: %w",
err)
return
} else if err != nil {
@@ -685,7 +685,7 @@ func openChannelPsbt(rpcCtx context.Context, ctx *cli.Context,
}
fundedPsbt, err := decodePsbt(inputPsbt)
if err != nil {
return fmt.Errorf("psbt decode failed: %v",
return fmt.Errorf("psbt decode failed: %w",
err)
}
verifyMsg := &lnrpc.FundingTransitionMsg{
@@ -873,14 +873,14 @@ func batchOpenChannel(ctx *cli.Context) error {
for idx, jsonChannel := range jsonChannels {
pubKeyBytes, err := hex.DecodeString(jsonChannel.NodePubkey)
if err != nil {
return fmt.Errorf("error parsing node pubkey hex: %v",
return fmt.Errorf("error parsing node pubkey hex: %w",
err)
}
pendingChanBytes, err := hex.DecodeString(
jsonChannel.PendingChanID,
)
if err != nil {
return fmt.Errorf("error parsing pending chan ID: %v",
return fmt.Errorf("error parsing pending chan ID: %w",
err)
}

View File

@@ -525,13 +525,13 @@ func sendPaymentRequest(ctx *cli.Context,
recordID, err := strconv.ParseUint(kv[0], 10, 64)
if err != nil {
return fmt.Errorf("invalid data format: %v",
return fmt.Errorf("invalid data format: %w",
err)
}
hexValue, err := hex.DecodeString(kv[1])
if err != nil {
return fmt.Errorf("invalid data format: %v",
return fmt.Errorf("invalid data format: %w",
err)
}
@@ -1514,7 +1514,7 @@ func forwardingHistory(ctx *cli.Context) error {
case args.Present():
i, err := strconv.ParseInt(args.First(), 10, 64)
if err != nil {
return fmt.Errorf("unable to decode index_offset: %v",
return fmt.Errorf("unable to decode index_offset: %w",
err)
}
indexOffset = uint32(i)
@@ -1527,7 +1527,7 @@ func forwardingHistory(ctx *cli.Context) error {
case args.Present():
m, err := strconv.ParseInt(args.First(), 10, 64)
if err != nil {
return fmt.Errorf("unable to decode max_events: %v",
return fmt.Errorf("unable to decode max_events: %w",
err)
}
maxEvents = uint32(m)
@@ -1616,7 +1616,7 @@ func buildRoute(ctx *cli.Context) error {
for _, k := range hops {
pubkey, err := route.NewVertexFromStr(k)
if err != nil {
return fmt.Errorf("error parsing %v: %v", k, err)
return fmt.Errorf("error parsing %v: %w", k, err)
}
rpcHops = append(rpcHops, pubkey[:])
}
@@ -1757,7 +1757,7 @@ func deletePayments(ctx *cli.Context) error {
case singlePayment:
paymentHash, err = hex.DecodeString(ctx.String("payment_hash"))
if err != nil {
return fmt.Errorf("error decoding payment_hash: %v",
return fmt.Errorf("error decoding payment_hash: %w",
err)
}
@@ -1766,7 +1766,7 @@ func deletePayments(ctx *cli.Context) error {
FailedHtlcsOnly: failedHTLCsOnly,
})
if err != nil {
return fmt.Errorf("error deleting single payment: %v",
return fmt.Errorf("error deleting single payment: %w",
err)
}

View File

@@ -150,7 +150,7 @@ func profileAdd(ctx *cli.Context) error {
// All done, store the updated profile file.
f.Profiles = append(f.Profiles, profile)
if err = saveProfileFile(defaultProfileFile, f); err != nil {
return fmt.Errorf("error writing profile file %s: %v",
return fmt.Errorf("error writing profile file %s: %w",
defaultProfileFile, err)
}
@@ -443,7 +443,7 @@ func profileAddMacaroon(ctx *cli.Context) error {
selectedProfile.Macaroons.Jar, macEntry,
)
if err = saveProfileFile(defaultProfileFile, f); err != nil {
return fmt.Errorf("error writing profile file %s: %v",
return fmt.Errorf("error writing profile file %s: %w",
defaultProfileFile, err)
}

View File

@@ -1811,7 +1811,7 @@ func getChanInfo(ctx *cli.Context) error {
case ctx.Args().Present():
chanID, err = strconv.ParseUint(ctx.Args().First(), 10, 64)
if err != nil {
return fmt.Errorf("error parsing chan_id: %s", err)
return fmt.Errorf("error parsing chan_id: %w", err)
}
default:
return fmt.Errorf("chan_id argument missing")

View File

@@ -67,7 +67,7 @@ func (e *macaroonEntry) loadMacaroon(
macBytes, err = decryptMacaroon(parts[1], parts[2], pw)
if err != nil {
return nil, fmt.Errorf("unable to decrypt macaroon: %v",
return nil, fmt.Errorf("unable to decrypt macaroon: %w",
err)
}
} else {
@@ -142,7 +142,7 @@ func decryptMacaroon(keyB64, dataB64 string, pw []byte) ([]byte, error) {
key := &snacl.SecretKey{}
err = key.Unmarshal(keyData)
if err != nil {
return nil, fmt.Errorf("could not unmarshal encryption key: %v",
return nil, fmt.Errorf("could not unmarshal encryption key: %w",
err)
}
@@ -155,7 +155,7 @@ func decryptMacaroon(keyB64, dataB64 string, pw []byte) ([]byte, error) {
}
macBytes, err := key.Decrypt(encryptedMac)
if err != nil {
return nil, fmt.Errorf("could not decrypt macaroon data: %v",
return nil, fmt.Errorf("could not decrypt macaroon data: %w",
err)
}
return macBytes, nil

View File

@@ -224,7 +224,7 @@ func loadProfileFile(file string) (*profileFile, error) {
content, err := ioutil.ReadFile(file)
if err != nil {
return nil, fmt.Errorf("could not load profile file %s: %v",
return nil, fmt.Errorf("could not load profile file %s: %w",
file, err)
}
f := &profileFile{}
@@ -262,7 +262,7 @@ func (f *profileFile) unmarshalJSON(content []byte) error {
func (f *profileFile) marshalJSON() ([]byte, error) {
b, err := json.Marshal(f)
if err != nil {
return nil, fmt.Errorf("error JSON marshalling profile: %v",
return nil, fmt.Errorf("error JSON marshalling profile: %w",
err)
}

View File

@@ -1235,8 +1235,8 @@ func fundPsbt(ctx *cli.Context) error {
// entry must be present.
jsonMap := []byte(ctx.String("outputs"))
if err := json.Unmarshal(jsonMap, &amountToAddr); err != nil {
return fmt.Errorf("error parsing outputs JSON: %v",
err)
return fmt.Errorf("error parsing outputs "+
"JSON: %w", err)
}
tpl.Outputs = amountToAddr
}