From 460d1be5a1ff6ff8ffe90ed4450d0d9a49addf75 Mon Sep 17 00:00:00 2001 From: martonp Date: Tue, 3 Dec 2024 17:42:41 +0100 Subject: [PATCH 1/2] libxc/binance: Better error message Return the actual error message in the error so it prints properly on the UI. --- client/mm/libxc/binance.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/mm/libxc/binance.go b/client/mm/libxc/binance.go index 28f1552a21..9336b3fde9 100644 --- a/client/mm/libxc/binance.go +++ b/client/mm/libxc/binance.go @@ -1330,8 +1330,12 @@ func (bnc *binance) request(ctx context.Context, method, endpoint string, query, } if err := dexnet.Do(req, thing, dexnet.WithSizeLimit(1<<24), dexnet.WithErrorParsing(&errPayload)); err != nil { bnc.log.Errorf("request error from endpoint %s %q with query = %q, body = %q", method, endpoint, queryString, bodyString) - return fmt.Errorf("%w, bn code = %d, msg = %q", err, errPayload.Code, errPayload.Msg) + if errPayload.Msg != "" { + return fmt.Errorf("Binance error: %v", errPayload.Msg) + } + return err } + return nil } From dd214733153496beadb1a41dd4d5d9f6e364c109 Mon Sep 17 00:00:00 2001 From: martonp Date: Sat, 7 Dec 2024 12:53:39 +0400 Subject: [PATCH 2/2] Joe review and other logging fixes --- client/mm/libxc/binance.go | 17 +++++++++-------- client/mm/mm.go | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/client/mm/libxc/binance.go b/client/mm/libxc/binance.go index 9336b3fde9..6a4eacc64b 100644 --- a/client/mm/libxc/binance.go +++ b/client/mm/libxc/binance.go @@ -566,7 +566,7 @@ func (bnc *binance) refreshBalances(ctx context.Context) error { var resp bntypes.Account err := bnc.getAPI(ctx, "/api/v3/account", nil, true, true, &resp) if err != nil { - return fmt.Errorf("error getting balances: %w", err) + return err } tokenIDsI := bnc.tokenIDs.Load() @@ -643,7 +643,7 @@ func (bnc *binance) getCoinInfo(ctx context.Context) error { coins := make([]*bntypes.CoinInfo, 0) err := bnc.getAPI(ctx, "/sapi/v1/capital/config/getall", nil, true, true, &coins) if err != nil { - return fmt.Errorf("error getting binance coin info: %w", err) + return err } bnc.readCoins(coins) @@ -654,7 +654,7 @@ func (bnc *binance) getMarkets(ctx context.Context) (map[string]*bntypes.Market, var exchangeInfo bntypes.ExchangeInfo err := bnc.getAPI(ctx, "/api/v3/exchangeInfo", nil, false, false, &exchangeInfo) if err != nil { - return nil, fmt.Errorf("error getting markets from Binance: %w", err) + return nil, err } marketsMap := make(map[string]*bntypes.Market, len(exchangeInfo.Symbols)) @@ -712,11 +712,11 @@ func (bnc *binance) Connect(ctx context.Context) (*sync.WaitGroup, error) { } if err := bnc.setBalances(ctx); err != nil { - return nil, err + return nil, fmt.Errorf("error getting balances") } if err := bnc.getUserDataStream(ctx); err != nil { - return nil, err + return nil, fmt.Errorf("error getting user data stream") } // Refresh balances periodically. This is just for safety as they should @@ -1329,9 +1329,10 @@ func (bnc *binance) request(ctx context.Context, method, endpoint string, query, Msg string `json:"msg"` } if err := dexnet.Do(req, thing, dexnet.WithSizeLimit(1<<24), dexnet.WithErrorParsing(&errPayload)); err != nil { - bnc.log.Errorf("request error from endpoint %s %q with query = %q, body = %q", method, endpoint, queryString, bodyString) + bnc.log.Errorf("request error from endpoint %s %q with query = %q, body = %q, err = %v, bn code = %d, msg = %q", + method, endpoint, queryString, bodyString, err, errPayload.Code, errPayload.Msg) if errPayload.Msg != "" { - return fmt.Errorf("Binance error: %v", errPayload.Msg) + return fmt.Errorf("Binance error: %v (%d)", errPayload.Msg, errPayload.Code) } return err } @@ -1513,7 +1514,7 @@ func (bnc *binance) getUserDataStream(ctx context.Context) (err error) { cm := dex.NewConnectionMaster(conn) if err = cm.ConnectOnce(ctx); err != nil { - return nil, fmt.Errorf("user data stream connection error: %v", err) + return nil, err } return cm, nil diff --git a/client/mm/mm.go b/client/mm/mm.go index c4f69b9076..3c16357c8a 100644 --- a/client/mm/mm.go +++ b/client/mm/mm.go @@ -648,7 +648,7 @@ func (m *MarketMaker) Connect(ctx context.Context) (*sync.WaitGroup, error) { // Try to connect so we can update our balances and set the // connected flag, but ignore errors. if err := m.connectCEX(ctx, c); err != nil { - m.log.Infof("Could not connect to %q: %w", cexCfg.Name, err) + m.log.Infof("Could not connect to %q: %v", cexCfg.Name, err) } } }