mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 09:48:19 +01:00
refactor: use errors.New to replace fmt.Errorf with no parameters
Signed-off-by: LesCyber <andi4cing@gmail.com>
This commit is contained in:
parent
f744a5477f
commit
6afcda712a
12 changed files with 27 additions and 29 deletions
|
@ -3,6 +3,7 @@ package amp
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
@ -139,7 +140,7 @@ func (s *ShardTracker) CancelShard(pid uint64) error {
|
||||||
|
|
||||||
c, ok := s.shards[pid]
|
c, ok := s.shards[pid]
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("pid not found")
|
return errors.New("pid not found")
|
||||||
}
|
}
|
||||||
delete(s.shards, pid)
|
delete(s.shards, pid)
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package amp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"fmt"
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// zeroShare is the all-zero 32-byte share.
|
// zeroShare is the all-zero 32-byte share.
|
||||||
|
@ -97,7 +97,7 @@ func (s *SeedSharer) Root() Share {
|
||||||
func (s *SeedSharer) Split() (Sharer, Sharer, error) {
|
func (s *SeedSharer) Split() (Sharer, Sharer, error) {
|
||||||
// We cannot split the zero-Sharer.
|
// We cannot split the zero-Sharer.
|
||||||
if s.curr == zeroShare {
|
if s.curr == zeroShare {
|
||||||
return nil, nil, fmt.Errorf("cannot split zero-Sharer")
|
return nil, nil, errors.New("cannot split zero-Sharer")
|
||||||
}
|
}
|
||||||
|
|
||||||
shareLeft, shareRight, err := split(&s.curr)
|
shareLeft, shareRight, err := split(&s.curr)
|
||||||
|
|
|
@ -5,7 +5,6 @@ package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
|
@ -80,7 +79,7 @@ func getBlock(ctx *cli.Context) error {
|
||||||
blockHashString = args.First()
|
blockHashString = args.First()
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("hash argument missing")
|
return errors.New("hash argument missing")
|
||||||
}
|
}
|
||||||
|
|
||||||
blockHash, err := chainhash.NewHashFromStr(blockHashString)
|
blockHash, err := chainhash.NewHashFromStr(blockHashString)
|
||||||
|
@ -233,7 +232,7 @@ func getBlockHash(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("block height argument missing")
|
return errors.New("block height argument missing")
|
||||||
}
|
}
|
||||||
|
|
||||||
client, cleanUp := getChainClient(ctx)
|
client, cleanUp := getChainClient(ctx)
|
||||||
|
|
|
@ -267,7 +267,7 @@ func actionDecorator(f func(*cli.Context) error) func(*cli.Context) error {
|
||||||
c.Command.Name == "changepassword" ||
|
c.Command.Name == "changepassword" ||
|
||||||
c.Command.Name == "createwatchonly") {
|
c.Command.Name == "createwatchonly") {
|
||||||
|
|
||||||
return fmt.Errorf("Wallet is already unlocked")
|
return errors.New("Wallet is already unlocked")
|
||||||
}
|
}
|
||||||
|
|
||||||
// lnd might be active, but not possible to contact
|
// lnd might be active, but not possible to contact
|
||||||
|
@ -277,7 +277,7 @@ func actionDecorator(f func(*cli.Context) error) func(*cli.Context) error {
|
||||||
// WalletUnlocker server active) and most likely this
|
// WalletUnlocker server active) and most likely this
|
||||||
// is because of an encrypted wallet.
|
// is because of an encrypted wallet.
|
||||||
if ok && s.Code() == codes.Unimplemented {
|
if ok && s.Code() == codes.Unimplemented {
|
||||||
return fmt.Errorf("Wallet is encrypted. " +
|
return errors.New("Wallet is encrypted. " +
|
||||||
"Please unlock using 'lncli unlock', " +
|
"Please unlock using 'lncli unlock', " +
|
||||||
"or set password using 'lncli create'" +
|
"or set password using 'lncli create'" +
|
||||||
" if this is the first time starting " +
|
" if this is the first time starting " +
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc/peersrpc"
|
"github.com/lightningnetwork/lnd/lnrpc/peersrpc"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
@ -147,7 +145,7 @@ func updateNodeAnnouncement(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !change {
|
if !change {
|
||||||
return fmt.Errorf("no changes for the node information " +
|
return errors.New("no changes for the node information " +
|
||||||
"detected")
|
"detected")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ func (e *profileEntry) cert() (*x509.CertPool, error) {
|
||||||
|
|
||||||
cp := x509.NewCertPool()
|
cp := x509.NewCertPool()
|
||||||
if !cp.AppendCertsFromPEM([]byte(e.TLSCert)) {
|
if !cp.AppendCertsFromPEM([]byte(e.TLSCert)) {
|
||||||
return nil, fmt.Errorf("credentials: failed to append " +
|
return nil, errors.New("credentials: failed to append " +
|
||||||
"certificate")
|
"certificate")
|
||||||
}
|
}
|
||||||
return cp, nil
|
return cp, nil
|
||||||
|
@ -140,7 +140,7 @@ func profileFromContext(ctx *cli.Context, store, skipMacaroons bool) (
|
||||||
for _, m := range ctx.GlobalStringSlice("metadata") {
|
for _, m := range ctx.GlobalStringSlice("metadata") {
|
||||||
pair := strings.Split(m, ":")
|
pair := strings.Split(m, ":")
|
||||||
if len(pair) != 2 {
|
if len(pair) != 2 {
|
||||||
return nil, fmt.Errorf("invalid format for metadata " +
|
return nil, errors.New("invalid format for metadata " +
|
||||||
"flag; expected \"key:value\"")
|
"flag; expected \"key:value\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1930,7 +1930,7 @@ func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{},
|
||||||
|
|
||||||
splitCookie := strings.Split(string(cookie), ":")
|
splitCookie := strings.Split(string(cookie), ":")
|
||||||
if len(splitCookie) != 2 {
|
if len(splitCookie) != 2 {
|
||||||
return fmt.Errorf("cookie file has a wrong " +
|
return errors.New("cookie file has a wrong " +
|
||||||
"format")
|
"format")
|
||||||
}
|
}
|
||||||
conf.RPCUser = splitCookie[0]
|
conf.RPCUser = splitCookie[0]
|
||||||
|
@ -1968,7 +1968,7 @@ func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{},
|
||||||
// the RPC credentials from the configuration. So if lnd wasn't
|
// the RPC credentials from the configuration. So if lnd wasn't
|
||||||
// specified the parameters, then we won't be able to start.
|
// specified the parameters, then we won't be able to start.
|
||||||
if cConfig.SimNet {
|
if cConfig.SimNet {
|
||||||
return fmt.Errorf("rpcuser and rpcpass must be set to your " +
|
return errors.New("rpcuser and rpcpass must be set to your " +
|
||||||
"btcd node's RPC parameters for simnet mode")
|
"btcd node's RPC parameters for simnet mode")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2097,7 +2097,7 @@ func extractBtcdRPCParams(btcdConfigPath string) (string, string, error) {
|
||||||
}
|
}
|
||||||
userSubmatches := rpcUserRegexp.FindSubmatch(configContents)
|
userSubmatches := rpcUserRegexp.FindSubmatch(configContents)
|
||||||
if userSubmatches == nil {
|
if userSubmatches == nil {
|
||||||
return "", "", fmt.Errorf("unable to find rpcuser in config")
|
return "", "", errors.New("unable to find rpcuser in config")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Similarly, we'll use another regular expression to find the set
|
// Similarly, we'll use another regular expression to find the set
|
||||||
|
|
|
@ -272,7 +272,7 @@ func (d *DefaultWalletImpl) ValidateMacaroon(ctx context.Context,
|
||||||
// Because the default implementation does not return any permissions,
|
// Because the default implementation does not return any permissions,
|
||||||
// we shouldn't be registered as an external validator at all and this
|
// we shouldn't be registered as an external validator at all and this
|
||||||
// should never be invoked.
|
// should never be invoked.
|
||||||
return fmt.Errorf("default implementation does not support external " +
|
return errors.New("default implementation does not support external " +
|
||||||
"macaroon validation")
|
"macaroon validation")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,7 +376,7 @@ func (d *DefaultWalletImpl) BuildWalletConfig(ctx context.Context,
|
||||||
if d.cfg.WalletUnlockPasswordFile != "" && !walletExists &&
|
if d.cfg.WalletUnlockPasswordFile != "" && !walletExists &&
|
||||||
!d.cfg.WalletUnlockAllowCreate {
|
!d.cfg.WalletUnlockAllowCreate {
|
||||||
|
|
||||||
return nil, nil, nil, fmt.Errorf("wallet unlock password file " +
|
return nil, nil, nil, errors.New("wallet unlock password file " +
|
||||||
"was specified but wallet does not exist; initialize " +
|
"was specified but wallet does not exist; initialize " +
|
||||||
"the wallet before using auto unlocking")
|
"the wallet before using auto unlocking")
|
||||||
}
|
}
|
||||||
|
@ -1173,7 +1173,7 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
if ripInvoices {
|
if ripInvoices {
|
||||||
err = fmt.Errorf("invoices bucket tombstoned, please " +
|
err = errors.New("invoices bucket tombstoned, please " +
|
||||||
"switch back to native SQL")
|
"switch back to native SQL")
|
||||||
d.logger.Error(err)
|
d.logger.Error(err)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package fn
|
package fn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ func RecvOrTimeout[T any](c <-chan T, timeout time.Duration) (T, error) {
|
||||||
|
|
||||||
case <-time.After(timeout):
|
case <-time.After(timeout):
|
||||||
var zero T
|
var zero T
|
||||||
return zero, fmt.Errorf("timeout hit")
|
return zero, errors.New("timeout hit")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,6 @@ func RecvResp[T any](r <-chan T, e <-chan error, q <-chan struct{}) (T, error) {
|
||||||
return noResp, err
|
return noResp, err
|
||||||
|
|
||||||
case <-q:
|
case <-q:
|
||||||
return noResp, fmt.Errorf("quitting")
|
return noResp, errors.New("quitting")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
pilot.go
2
pilot.go
|
@ -66,7 +66,7 @@ func validateAtplCfg(cfg *lncfg.AutoPilot) ([]*autopilot.WeightedHeuristic,
|
||||||
}
|
}
|
||||||
|
|
||||||
if sum != 1.0 {
|
if sum != 1.0 {
|
||||||
return nil, fmt.Errorf("heuristic weights must sum to 1.0")
|
return nil, errors.New("heuristic weights must sum to 1.0")
|
||||||
}
|
}
|
||||||
return heuristics, nil
|
return heuristics, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,7 +226,7 @@ var (
|
||||||
// If the --no-macaroons flag is used to start lnd, the macaroon service
|
// If the --no-macaroons flag is used to start lnd, the macaroon service
|
||||||
// is not initialized. errMacaroonDisabled is then returned when
|
// is not initialized. errMacaroonDisabled is then returned when
|
||||||
// macaroon related services are used.
|
// macaroon related services are used.
|
||||||
errMacaroonDisabled = fmt.Errorf("macaroon authentication disabled, " +
|
errMacaroonDisabled = errors.New("macaroon authentication disabled, " +
|
||||||
"remove --no-macaroons flag to enable")
|
"remove --no-macaroons flag to enable")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1355,7 +1355,7 @@ func (r *rpcServer) SendCoins(ctx context.Context,
|
||||||
decodedAddr, _ := hex.DecodeString(in.Addr)
|
decodedAddr, _ := hex.DecodeString(in.Addr)
|
||||||
_, err = btcec.ParsePubKey(decodedAddr)
|
_, err = btcec.ParsePubKey(decodedAddr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return nil, fmt.Errorf("cannot send coins to pubkeys")
|
return nil, errors.New("cannot send coins to pubkeys")
|
||||||
}
|
}
|
||||||
|
|
||||||
label, err := labels.ValidateAPI(in.Label)
|
label, err := labels.ValidateAPI(in.Label)
|
||||||
|
@ -1385,7 +1385,7 @@ func (r *rpcServer) SendCoins(ctx context.Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
if fn.HasDuplicates(wireOutpoints) {
|
if fn.HasDuplicates(wireOutpoints) {
|
||||||
return nil, fmt.Errorf("selected outpoints contain " +
|
return nil, errors.New("selected outpoints contain " +
|
||||||
"duplicate values")
|
"duplicate values")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1400,7 +1400,7 @@ func (r *rpcServer) SendCoins(ctx context.Context,
|
||||||
// At this point, the amount shouldn't be set since we've been
|
// At this point, the amount shouldn't be set since we've been
|
||||||
// instructed to sweep all the coins from the wallet.
|
// instructed to sweep all the coins from the wallet.
|
||||||
if in.Amount != 0 {
|
if in.Amount != 0 {
|
||||||
return nil, fmt.Errorf("amount set while SendAll is " +
|
return nil, errors.New("amount set while SendAll is " +
|
||||||
"active")
|
"active")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -572,7 +572,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
||||||
if cfg.ProtocolOptions.TaprootOverlayChans &&
|
if cfg.ProtocolOptions.TaprootOverlayChans &&
|
||||||
implCfg.AuxFundingController.IsNone() {
|
implCfg.AuxFundingController.IsNone() {
|
||||||
|
|
||||||
return nil, fmt.Errorf("taproot overlay flag set, but not " +
|
return nil, errors.New("taproot overlay flag set, but not " +
|
||||||
"aux controllers")
|
"aux controllers")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1428,7 +1428,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
||||||
|
|
||||||
if ourPolicy == nil {
|
if ourPolicy == nil {
|
||||||
// Something is wrong, so return an error.
|
// Something is wrong, so return an error.
|
||||||
return nil, fmt.Errorf("we don't have an edge")
|
return nil, errors.New("we don't have an edge")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.graphDB.DeleteChannelEdges(
|
err = s.graphDB.DeleteChannelEdges(
|
||||||
|
|
Loading…
Add table
Reference in a new issue