From 6027eacd71a273c9e2d41f353464c1b8c2608b08 Mon Sep 17 00:00:00 2001 From: gobicycle Date: Wed, 9 Oct 2024 17:43:17 +0300 Subject: [PATCH] db err check --- db/db.go | 37 ++++++++++++++++++++++++++++++++++++- db/db_test.go | 6 ++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/db/db.go b/db/db.go index 39188a1..d95cc03 100644 --- a/db/db.go +++ b/db/db.go @@ -225,6 +225,9 @@ func (c *Connection) GetTonWalletsAddresses( } res = append(res, a) } + if rows.Err() != nil { + return nil, rows.Err() + } return res, nil } @@ -258,6 +261,9 @@ func (c *Connection) GetJettonOwnersAddresses( } res = append(res, ow) } + if rows.Err() != nil { + return nil, rows.Err() + } return res, nil } @@ -284,7 +290,9 @@ func (c *Connection) LoadAddressBook(ctx context.Context) error { } res[addr] = core.AddressInfo{Type: t, Owner: nil, UserID: userID} } - + if rows.Err() != nil { + return rows.Err() + } rows, err = c.client.Query(ctx, ` SELECT jw.address, jw.type, tw.address, jw.user_id FROM payments.jetton_wallets jw @@ -302,6 +310,9 @@ func (c *Connection) LoadAddressBook(ctx context.Context) error { } res[addr] = core.AddressInfo{Type: t, Owner: &owner, UserID: userID} } + if rows.Err() != nil { + return rows.Err() + } c.addressBook.addresses = res log.Info("Address book loaded") @@ -491,6 +502,9 @@ func (c *Connection) GetExternalWithdrawalTasks(ctx context.Context, limit int) } res = append(res, w) } + if rows.Err() != nil { + return nil, rows.Err() + } return res, nil } @@ -520,6 +534,9 @@ func (c *Connection) GetServiceHotWithdrawalTasks(ctx context.Context, limit int } tasks = append(tasks, w) } + if rows.Err() != nil { + return nil, rows.Err() + } return tasks, nil } @@ -550,6 +567,9 @@ func (c *Connection) GetServiceDepositWithdrawalTasks(ctx context.Context, limit } tasks = append(tasks, w) } + if rows.Err() != nil { + return nil, rows.Err() + } return tasks, nil } @@ -729,6 +749,9 @@ func (c *Connection) GetTonInternalWithdrawalTasks(ctx context.Context, limit in task.Currency = core.TonSymbol tasks = append(tasks, task) } + if rows.Err() != nil { + return nil, rows.Err() + } return tasks, nil } @@ -776,6 +799,9 @@ func (c *Connection) GetJettonInternalWithdrawalTasks( } tasks = append(tasks, task) } + if rows.Err() != nil { + return nil, rows.Err() + } return tasks, nil } @@ -997,6 +1023,9 @@ func (c *Connection) SetExpired(ctx context.Context) error { } ids = append(ids, queryID) } + if rows.Err() != nil { + return rows.Err() + } for _, id := range ids { _, err = tx.Exec(ctx, ` @@ -1164,6 +1193,9 @@ func (c *Connection) GetIncome( } res = append(res, deposit) } + if rows.Err() != nil { + return nil, rows.Err() + } return res, nil } @@ -1231,6 +1263,9 @@ func (c *Connection) GetIncomeHistory( income.Utime = uint32(t.Unix()) res = append(res, income) } + if rows.Err() != nil { + return nil, rows.Err() + } return res, nil } diff --git a/db/db_test.go b/db/db_test.go index 6d3176f..92285d9 100644 --- a/db/db_test.go +++ b/db/db_test.go @@ -221,6 +221,9 @@ func Test_SetExpired(t *testing.T) { extRes[i] = r i++ } + if rows.Err() != nil { + t.Fatal("rows err: ", rows.Err()) + } if externalResult != extRes { t.Fatalf("invalid external result pattern: %v", extRes) } @@ -246,6 +249,9 @@ func Test_SetExpired(t *testing.T) { intRes[i] = r i++ } + if rows.Err() != nil { + t.Fatal("rows err: ", rows.Err()) + } if internalResult != intRes { t.Fatalf("invalid internal result pattern: %v", intRes) }