Skip to content

Commit

Permalink
fix: return an explicit error instead of panic and optimize the error…
Browse files Browse the repository at this point in the history
… log (#339) (#341)
  • Loading branch information
Shawn-Huang-Tron authored Jul 28, 2023
1 parent 58978cb commit a791ada
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
5 changes: 3 additions & 2 deletions chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/bittorrent/go-btfs/chain/tokencfg"
"io"
"math/big"
"strings"
"time"

"github.com/bittorrent/go-btfs/chain/tokencfg"

"github.com/bittorrent/go-btfs/accounting"
"github.com/bittorrent/go-btfs/chain/config"
"github.com/bittorrent/go-btfs/settlement"
Expand Down Expand Up @@ -348,7 +349,7 @@ func initSwap(
priceOracle := priceoracle.New(currentPriceOracleAddress, transactionService)
_, err := priceOracle.CheckNewPrice(tokencfg.GetWbttToken()) // CheckNewPrice when node starts
if err != nil {
return nil, nil, errors.New("CheckNewPrice " + err.Error())
return nil, nil, errors.New("CheckNewPrice error, it may happens when contract call failed if bttc chain rpc is down, please try again")
}

swapProtocol := swapprotocol.New(overlayEthAddress, priceOracle)
Expand Down
2 changes: 1 addition & 1 deletion core/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"sort"
"strings"

"github.com/bittorrent/go-btfs-cmds"
cmds "github.com/bittorrent/go-btfs-cmds"
)

type commandEncoder struct {
Expand Down
17 changes: 14 additions & 3 deletions core/commands/storage/upload/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import (
"context"
"errors"
"fmt"
"github.com/bittorrent/go-btfs/chain/tokencfg"
"github.com/bittorrent/go-btfs/utils"
"strconv"
"strings"
"time"

"github.com/bittorrent/go-btfs/chain/tokencfg"
"github.com/bittorrent/go-btfs/utils"
coreiface "github.com/bittorrent/interface-go-btfs-core"

"github.com/bittorrent/go-btfs/settlement/swap/swapprotocol"

"github.com/bittorrent/go-btfs/chain"
"github.com/bittorrent/go-btfs/core/commands/cmdenv"
"github.com/bittorrent/go-btfs/core/commands/storage/hosts"
"github.com/bittorrent/go-btfs/core/commands/storage/upload/helper"
"github.com/bittorrent/go-btfs/core/commands/storage/upload/offline"
Expand Down Expand Up @@ -111,7 +114,15 @@ Use status command to check for completion:
},
RunTimeout: 15 * time.Minute,
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
err := utils.CheckSimpleMode(env)
nd, err := cmdenv.GetNode(env)
if err != nil {
return err
}

if !nd.IsOnline {
return coreiface.ErrOffline
}
err = utils.CheckSimpleMode(env)
if err != nil {
return err
}
Expand Down

0 comments on commit a791ada

Please sign in to comment.