Cleanup non-needed log.Fatal's in various files

This commit is contained in:
Adrian Gallagher
2019-01-17 14:10:56 +11:00
parent 84a67359c9
commit 7413fc41b8
6 changed files with 73 additions and 64 deletions

View File

@@ -367,7 +367,7 @@ func (c *Config) UpdateCommunicationsConfig(config CommunicationsConfig) {
// CheckCommunicationsConfig checks to see if the variables are set correctly
// from config.json
func (c *Config) CheckCommunicationsConfig() error {
func (c *Config) CheckCommunicationsConfig() {
m.Lock()
defer m.Unlock()
@@ -455,20 +455,22 @@ func (c *Config) CheckCommunicationsConfig() error {
c.Communications.SMSGlobalConfig.Name != "SMSGlobal" ||
c.Communications.SMTPConfig.Name != "SMTP" ||
c.Communications.TelegramConfig.Name != "Telegram" {
return errors.New("Communications config name/s not set correctly")
log.Warn("Communications config name/s not set correctly")
}
if c.Communications.SlackConfig.Enabled {
if c.Communications.SlackConfig.TargetChannel == "" ||
c.Communications.SlackConfig.VerificationToken == "" ||
c.Communications.SlackConfig.VerificationToken == "testtest" {
return errors.New("Slack enabled in config but variable data not set")
c.Communications.SlackConfig.Enabled = false
log.Warn("Slack enabled in config but variable data not set, disabling.")
}
}
if c.Communications.SMSGlobalConfig.Enabled {
if c.Communications.SMSGlobalConfig.Username == "" ||
c.Communications.SMSGlobalConfig.Password == "" ||
len(c.Communications.SMSGlobalConfig.Contacts) == 0 {
return errors.New("SMSGlobal enabled in config but variable data not set")
c.Communications.SMSGlobalConfig.Enabled = false
log.Warn("SMSGlobal enabled in config but variable data not set, disabling.")
}
}
if c.Communications.SMTPConfig.Enabled {
@@ -476,15 +478,16 @@ func (c *Config) CheckCommunicationsConfig() error {
c.Communications.SMTPConfig.Port == "" ||
c.Communications.SMTPConfig.AccountName == "" ||
c.Communications.SMTPConfig.AccountPassword == "" {
return errors.New("SMTP enabled in config but variable data not set")
c.Communications.SMTPConfig.Enabled = false
log.Warn("SMTP enabled in config but variable data not set, disabling.")
}
}
if c.Communications.TelegramConfig.Enabled {
if c.Communications.TelegramConfig.VerificationToken == "" {
return errors.New("Telegram enabled in config but variable data not set")
c.Communications.TelegramConfig.Enabled = false
log.Warn("Telegram enabled in config but variable data not set, disabling.")
}
}
return nil
}
// CheckPairConsistency checks to see if the enabled pair exists in the
@@ -1196,9 +1199,7 @@ func (c *Config) CheckConfig() error {
return fmt.Errorf(ErrCheckingConfigValues, err)
}
if err = c.CheckCommunicationsConfig(); err != nil {
log.Fatal(err)
}
c.CheckCommunicationsConfig()
if c.Webserver.Enabled {
err = c.CheckWebserverConfigValues()

View File

@@ -189,10 +189,7 @@ func TestCheckCommunicationsConfig(t *testing.T) {
}
cfg.Communications = CommunicationsConfig{}
err = cfg.CheckCommunicationsConfig()
if err != nil {
t.Error("Test failed. CheckCommunicationsConfig error:", err)
}
cfg.CheckCommunicationsConfig()
if cfg.Communications.SlackConfig.Name != "Slack" ||
cfg.Communications.SMSGlobalConfig.Name != "SMSGlobal" ||
cfg.Communications.SMTPConfig.Name != "SMTP" ||
@@ -203,8 +200,8 @@ func TestCheckCommunicationsConfig(t *testing.T) {
cfg.SMS = &SMSGlobalConfig{}
cfg.Communications.SMSGlobalConfig.Name = ""
err = cfg.CheckCommunicationsConfig()
if err != nil || cfg.Communications.SMSGlobalConfig.Password != "test" {
cfg.CheckCommunicationsConfig()
if cfg.Communications.SMSGlobalConfig.Password != "test" {
t.Error("Test failed. CheckCommunicationsConfig error:", err)
}
@@ -214,56 +211,50 @@ func TestCheckCommunicationsConfig(t *testing.T) {
Enabled: false,
})
cfg.Communications.SMSGlobalConfig.Name = ""
err = cfg.CheckCommunicationsConfig()
if err != nil || cfg.Communications.SMSGlobalConfig.Contacts[0].Name != "Bobby" {
cfg.CheckCommunicationsConfig()
if cfg.Communications.SMSGlobalConfig.Contacts[0].Name != "Bobby" {
t.Error("Test failed. CheckCommunicationsConfig error:", err)
}
cfg.SMS = &SMSGlobalConfig{}
err = cfg.CheckCommunicationsConfig()
if err != nil {
t.Error("Test failed. CheckCommunicationsConfig error:", err)
}
cfg.CheckCommunicationsConfig()
if cfg.SMS != nil {
t.Error("Test failed. CheckCommunicationsConfig unexpected data:",
cfg.SMS)
}
cfg.Communications.SlackConfig.Name = "NOT Slack"
err = cfg.CheckCommunicationsConfig()
if err.Error() != "Communications config name/s not set correctly" {
t.Error("Test failed. CheckCommunicationsConfig unexpected error:", err)
}
cfg.CheckCommunicationsConfig()
cfg.Communications.SlackConfig.Name = "Slack"
cfg.Communications.SlackConfig.Enabled = true
err = cfg.CheckCommunicationsConfig()
if err.Error() != "Slack enabled in config but variable data not set" {
t.Error("Test failed. CheckCommunicationsConfig unexpected error:", err)
cfg.CheckCommunicationsConfig()
if cfg.Communications.SlackConfig.Enabled {
t.Error("Test failed. CheckCommunicationsConfig Slack is enabled when it shouldn't be.")
}
cfg.Communications.SlackConfig.Enabled = false
cfg.Communications.SMSGlobalConfig.Enabled = true
cfg.Communications.SMSGlobalConfig.Password = ""
err = cfg.CheckCommunicationsConfig()
if err.Error() != "SMSGlobal enabled in config but variable data not set" {
t.Error("Test failed. CheckCommunicationsConfig unexpected error:", err)
cfg.CheckCommunicationsConfig()
if cfg.Communications.SlackConfig.Enabled {
t.Error("Test failed. CheckCommunicationsConfig SMSGlobal is enabled when it shouldn't be.")
}
cfg.Communications.SMSGlobalConfig.Enabled = false
cfg.Communications.SMTPConfig.Enabled = true
cfg.Communications.SMTPConfig.AccountPassword = ""
err = cfg.CheckCommunicationsConfig()
if err.Error() != "SMTP enabled in config but variable data not set" {
t.Error("Test failed. CheckCommunicationsConfig unexpected error:", err)
cfg.CheckCommunicationsConfig()
if cfg.Communications.SlackConfig.Enabled {
t.Error("Test failed. CheckCommunicationsConfig SMTPConfig is enabled when it shouldn't be.")
}
cfg.Communications.SMTPConfig.Enabled = false
cfg.Communications.TelegramConfig.Enabled = true
cfg.Communications.TelegramConfig.VerificationToken = ""
err = cfg.CheckCommunicationsConfig()
if err.Error() != "Telegram enabled in config but variable data not set" {
t.Error("Test failed. CheckCommunicationsConfig unexpected error:", err)
cfg.CheckCommunicationsConfig()
if cfg.Communications.TelegramConfig.Enabled {
t.Error("Test failed. CheckCommunicationsConfig TelegramConfig is enabled when it shouldn't be.")
}
}

View File

@@ -191,7 +191,8 @@ func (b *Bitstamp) WsReadData() {
result := PusherOrderbook{}
err := common.JSONDecode([]byte(data.Data), &result)
if err != nil {
log.Fatal(err)
b.Websocket.DataHandler <- err
continue
}
currencyPair := common.SplitStrings(data.Channel, "_")
@@ -200,6 +201,7 @@ func (b *Bitstamp) WsReadData() {
err = b.WsUpdateOrderbook(result, p, "SPOT")
if err != nil {
b.Websocket.DataHandler <- err
continue
}
case trade := <-b.WebsocketConn.Trade:
@@ -208,7 +210,8 @@ func (b *Bitstamp) WsReadData() {
result := PusherTrade{}
err := common.JSONDecode([]byte(trade.Data), &result)
if err != nil {
log.Fatal(err)
b.Websocket.DataHandler <- err
continue
}
currencyPair := common.SplitStrings(trade.Channel, "_")
@@ -235,12 +238,14 @@ func (b *Bitstamp) WsUpdateOrderbook(ob PusherOrderbook, p pair.CurrencyPair, as
for _, ask := range ob.Asks {
target, err := strconv.ParseFloat(ask[0], 64)
if err != nil {
log.Fatal(err)
b.Websocket.DataHandler <- err
continue
}
amount, err := strconv.ParseFloat(ask[1], 64)
if err != nil {
log.Fatal(err)
b.Websocket.DataHandler <- err
continue
}
asks = append(asks, orderbook.Item{Price: target, Amount: amount})
@@ -251,12 +256,14 @@ func (b *Bitstamp) WsUpdateOrderbook(ob PusherOrderbook, p pair.CurrencyPair, as
for _, bid := range ob.Bids {
target, err := strconv.ParseFloat(bid[0], 64)
if err != nil {
log.Fatal(err)
b.Websocket.DataHandler <- err
continue
}
amount, err := strconv.ParseFloat(bid[1], 64)
if err != nil {
log.Fatal(err)
b.Websocket.DataHandler <- err
continue
}
bids = append(bids, orderbook.Item{Price: target, Amount: amount})

View File

@@ -125,7 +125,8 @@ func (b *BTCC) WsHandleData() {
var Result WsResponseMain
err := common.JSONDecode(resp.Raw, &Result)
if err != nil {
log.Fatal(err)
b.Websocket.DataHandler <- err
continue
}
switch Result.MsgType {

View File

@@ -13,7 +13,6 @@ import (
"github.com/thrasher-/gocryptotrader/currency/pair"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
log "github.com/thrasher-/gocryptotrader/logger"
)
const (
@@ -143,7 +142,8 @@ func (c *CoinbasePro) WsHandleData() {
msgType := MsgType{}
err := common.JSONDecode(resp.Raw, &msgType)
if err != nil {
log.Fatal(err)
c.Websocket.DataHandler <- err
continue
}
if msgType.Type == "subscriptions" || msgType.Type == "heartbeat" {
@@ -158,7 +158,8 @@ func (c *CoinbasePro) WsHandleData() {
ticker := WebsocketTicker{}
err := common.JSONDecode(resp.Raw, &ticker)
if err != nil {
log.Fatal(err)
c.Websocket.DataHandler <- err
continue
}
c.Websocket.DataHandler <- exchange.TickerData{
@@ -176,28 +177,29 @@ func (c *CoinbasePro) WsHandleData() {
snapshot := WebsocketOrderbookSnapshot{}
err := common.JSONDecode(resp.Raw, &snapshot)
if err != nil {
log.Fatal(err)
c.Websocket.DataHandler <- err
continue
}
err = c.ProcessSnapshot(snapshot)
if err != nil {
log.Fatal(err)
c.Websocket.DataHandler <- err
continue
}
case "l2update":
update := WebsocketL2Update{}
err := common.JSONDecode(resp.Raw, &update)
if err != nil {
log.Fatal(err)
c.Websocket.DataHandler <- err
continue
}
err = c.ProcessUpdate(update)
if err != nil {
log.Fatal(err)
c.Websocket.DataHandler <- err
continue
}
default:
log.Fatal("Edge test", string(resp.Raw))
}
}
}

View File

@@ -12,7 +12,6 @@ import (
"github.com/thrasher-/gocryptotrader/currency/pair"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
log "github.com/thrasher-/gocryptotrader/logger"
)
const coinutWebsocketURL = "wss://wsapi.coinut.com"
@@ -73,7 +72,8 @@ func (c *COINUT) WsHandleData() {
var incoming wsResponse
err := common.JSONDecode(resp.Raw, &incoming)
if err != nil {
log.Fatal(err)
c.Websocket.DataHandler <- err
continue
}
switch incoming.Reply {
@@ -84,7 +84,8 @@ func (c *COINUT) WsHandleData() {
var ticker WsTicker
err := common.JSONDecode(resp.Raw, &ticker)
if err != nil {
log.Fatal(err)
c.Websocket.DataHandler <- err
continue
}
c.Websocket.DataHandler <- exchange.TickerData{
@@ -101,12 +102,14 @@ func (c *COINUT) WsHandleData() {
var orderbooksnapshot WsOrderbookSnapshot
err := common.JSONDecode(resp.Raw, &orderbooksnapshot)
if err != nil {
log.Fatal(err)
c.Websocket.DataHandler <- err
continue
}
err = c.WsProcessOrderbookSnapshot(orderbooksnapshot)
if err != nil {
log.Fatal(err)
c.Websocket.DataHandler <- err
continue
}
currencyPair := instrumentListByCode[orderbooksnapshot.InstID]
@@ -121,12 +124,14 @@ func (c *COINUT) WsHandleData() {
var orderbookUpdate WsOrderbookUpdate
err := common.JSONDecode(resp.Raw, &orderbookUpdate)
if err != nil {
log.Fatal(err)
c.Websocket.DataHandler <- err
continue
}
err = c.WsProcessOrderbookUpdate(orderbookUpdate)
if err != nil {
log.Fatal(err)
c.Websocket.DataHandler <- err
continue
}
currencyPair := instrumentListByCode[orderbookUpdate.InstID]
@@ -141,14 +146,16 @@ func (c *COINUT) WsHandleData() {
var tradeSnap WsTradeSnapshot
err := common.JSONDecode(resp.Raw, &tradeSnap)
if err != nil {
log.Fatal(err)
c.Websocket.DataHandler <- err
continue
}
case "inst_trade_update":
var tradeUpdate WsTradeUpdate
err := common.JSONDecode(resp.Raw, &tradeUpdate)
if err != nil {
log.Fatal(err)
c.Websocket.DataHandler <- err
continue
}
currencyPair := instrumentListByCode[tradeUpdate.InstID]