mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 01:36:24 +01:00
refactor: unify the error handling methods that are different from the project style
Signed-off-by: LesCyber <andi4cing@gmail.com>
This commit is contained in:
parent
6afcda712a
commit
adf7fb2131
6 changed files with 12 additions and 9 deletions
|
@ -3,6 +3,7 @@ package funding
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -1112,7 +1113,7 @@ func (f *Manager) advanceFundingState(channel *channeldb.OpenChannel,
|
||||||
channelState, shortChanID, err := f.getChannelOpeningState(
|
channelState, shortChanID, err := f.getChannelOpeningState(
|
||||||
&channel.FundingOutpoint,
|
&channel.FundingOutpoint,
|
||||||
)
|
)
|
||||||
if err == channeldb.ErrChannelNotFound {
|
if errors.Is(err, channeldb.ErrChannelNotFound) {
|
||||||
// Channel not in fundingManager's opening database,
|
// Channel not in fundingManager's opening database,
|
||||||
// meaning it was successfully announced to the
|
// meaning it was successfully announced to the
|
||||||
// network.
|
// network.
|
||||||
|
@ -1326,7 +1327,7 @@ func (f *Manager) advancePendingChannelState(channel *channeldb.OpenChannel,
|
||||||
}
|
}
|
||||||
|
|
||||||
confChannel, err := f.waitForFundingWithTimeout(channel)
|
confChannel, err := f.waitForFundingWithTimeout(channel)
|
||||||
if err == ErrConfirmationTimeout {
|
if errors.Is(err, ErrConfirmationTimeout) {
|
||||||
return f.fundingTimeout(channel, pendingChanID)
|
return f.fundingTimeout(channel, pendingChanID)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return fmt.Errorf("error waiting for funding "+
|
return fmt.Errorf("error waiting for funding "+
|
||||||
|
|
|
@ -1076,7 +1076,7 @@ func (c *ChannelGraph) AddChannelEdge(edge *models.ChannelEdgeInfo,
|
||||||
|
|
||||||
// Silence ErrEdgeAlreadyExist so that the batch can
|
// Silence ErrEdgeAlreadyExist so that the batch can
|
||||||
// succeed, but propagate the error via local state.
|
// succeed, but propagate the error via local state.
|
||||||
if err == ErrEdgeAlreadyExist {
|
if errors.Is(err, ErrEdgeAlreadyExist) {
|
||||||
alreadyExists = true
|
alreadyExists = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -3493,7 +3493,7 @@ func (c *ChannelGraph) FetchChannelEdgesByID(chanID uint64) (
|
||||||
policy1 = nil
|
policy1 = nil
|
||||||
policy2 = nil
|
policy2 = nil
|
||||||
})
|
})
|
||||||
if err == ErrZombieEdge {
|
if errors.Is(err, ErrZombieEdge) {
|
||||||
return edgeInfo, nil, nil, err
|
return edgeInfo, nil, nil, err
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -5,6 +5,7 @@ package lnrpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
|
@ -500,7 +501,7 @@ func IsClosedConnError(err error) bool {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if err == http.ErrServerClosed {
|
if errors.Is(err, http.ErrServerClosed) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4001,7 +4001,7 @@ func (p *Brontide) handleCloseMsg(msg *closeMsg) {
|
||||||
chanCloser, err := p.fetchActiveChanCloser(msg.cid)
|
chanCloser, err := p.fetchActiveChanCloser(msg.cid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If the channel is not known to us, we'll simply ignore this message.
|
// If the channel is not known to us, we'll simply ignore this message.
|
||||||
if err == ErrChannelNotFound {
|
if errors.Is(err, ErrChannelNotFound) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1440,7 +1440,7 @@ func (r *rpcServer) SendCoins(ctx context.Context,
|
||||||
// If sending everything to this address would invalidate our
|
// If sending everything to this address would invalidate our
|
||||||
// reserved wallet balance, we create a new sweep tx, where
|
// reserved wallet balance, we create a new sweep tx, where
|
||||||
// we'll send the reserved value back to our wallet.
|
// we'll send the reserved value back to our wallet.
|
||||||
if err == lnwallet.ErrReservedValueInvalidated {
|
if errors.Is(err, lnwallet.ErrReservedValueInvalidated) {
|
||||||
sweepTxPkg.CancelSweepAttempt()
|
sweepTxPkg.CancelSweepAttempt()
|
||||||
|
|
||||||
rpcsLog.Debugf("Reserved value %v not satisfied after "+
|
rpcsLog.Debugf("Reserved value %v not satisfied after "+
|
||||||
|
@ -4348,7 +4348,7 @@ func (r *rpcServer) nurseryPopulateForceCloseResp(chanPoint *wire.OutPoint,
|
||||||
// didn't have any time-locked outputs, then the nursery may not know of
|
// didn't have any time-locked outputs, then the nursery may not know of
|
||||||
// the contract.
|
// the contract.
|
||||||
nurseryInfo, err := r.server.utxoNursery.NurseryReport(chanPoint)
|
nurseryInfo, err := r.server.utxoNursery.NurseryReport(chanPoint)
|
||||||
if err == contractcourt.ErrContractNotFound {
|
if errors.Is(err, contractcourt.ErrContractNotFound) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
prand "math/rand"
|
prand "math/rand"
|
||||||
|
@ -4906,7 +4907,7 @@ func (s *server) DisconnectPeer(pubKey *btcec.PublicKey) error {
|
||||||
// exit in an error as we can't disconnect from a peer that we're not
|
// exit in an error as we can't disconnect from a peer that we're not
|
||||||
// currently connected to.
|
// currently connected to.
|
||||||
peer, err := s.findPeerByPubStr(pubStr)
|
peer, err := s.findPeerByPubStr(pubStr)
|
||||||
if err == ErrPeerNotConnected {
|
if errors.Is(err, ErrPeerNotConnected) {
|
||||||
return fmt.Errorf("peer %x is not connected", pubBytes)
|
return fmt.Errorf("peer %x is not connected", pubBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue