From c25e9224b61f936904324e225b1597ecf836de9a Mon Sep 17 00:00:00 2001 From: ditatompel Date: Fri, 24 May 2024 05:37:27 +0700 Subject: [PATCH] lint: No err check --- cmd/client/probe.go | 17 ++++++++++++----- cmd/server/probers.go | 6 +++++- internal/database/schema.go | 8 ++++++-- internal/monero/monero.go | 22 ++++++++++++++++------ 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/cmd/client/probe.go b/cmd/client/probe.go index cdaa77f..81d4b17 100644 --- a/cmd/client/probe.go +++ b/cmd/client/probe.go @@ -166,21 +166,27 @@ func (p *proberClient) fetchNode(node monero.Node) (monero.Node, error) { resp, err := client.Do(req) if err != nil { p.message = err.Error() - p.reportResult(node, time.Since(startTime).Seconds()) + if err := p.reportResult(node, time.Since(startTime).Seconds()); err != nil { + return node, err + } return node, err } defer resp.Body.Close() if resp.StatusCode != 200 { p.message = fmt.Sprintf("status code: %d", resp.StatusCode) - p.reportResult(node, time.Since(startTime).Seconds()) + if err := p.reportResult(node, time.Since(startTime).Seconds()); err != nil { + return node, err + } return node, errors.New(p.message) } body, err := io.ReadAll(resp.Body) if err != nil { p.message = err.Error() - p.reportResult(node, time.Since(startTime).Seconds()) + if err := p.reportResult(node, time.Since(startTime).Seconds()); err != nil { + return node, err + } return node, err } @@ -190,8 +196,9 @@ func (p *proberClient) fetchNode(node monero.Node) (monero.Node, error) { if err := json.Unmarshal(body, &reportNode); err != nil { p.message = err.Error() - p.reportResult(node, time.Since(startTime).Seconds()) - return node, err + if err := p.reportResult(node, time.Since(startTime).Seconds()); err != nil { + return node, err + } } if reportNode.Status == "OK" { node.IsAvailable = true diff --git a/cmd/server/probers.go b/cmd/server/probers.go index 55bcf9f..5acc2a2 100644 --- a/cmd/server/probers.go +++ b/cmd/server/probers.go @@ -3,6 +3,7 @@ package server import ( "bufio" "fmt" + "log/slog" "os" "strconv" "strings" @@ -22,7 +23,10 @@ var probersCmd = &cobra.Command{ This command should only be run on the server which directly connect to the MySQL database. `, Run: func(cmd *cobra.Command, _ []string) { - cmd.Help() + if err := cmd.Help(); err != nil { + slog.Error(err.Error()) + os.Exit(1) + } }, } diff --git a/internal/database/schema.go b/internal/database/schema.go index 846aa9d..bae23eb 100644 --- a/internal/database/schema.go +++ b/internal/database/schema.go @@ -29,7 +29,9 @@ func MigrateDb(db *DB) error { slog.Info(fmt.Sprintf("[DB] Migrating database schema version %d", version+1)) if err := migrateFn(db); err != nil { - tx.Rollback() + if err := tx.Rollback(); err != nil { + return err + } return err } if err := setSchemaVersion(db, version+1); err != nil { @@ -52,7 +54,9 @@ func getSchemaVersion(db *DB) int { return -1 } version := 0 - db.Get(&version, `SELECT version FROM tbl_schema_ver`) + if err := db.Get(&version, `SELECT version FROM tbl_schema_ver`); err != nil { + return -1 + } return version } diff --git a/internal/monero/monero.go b/internal/monero/monero.go index 144fb05..3f9a013 100644 --- a/internal/monero/monero.go +++ b/internal/monero/monero.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "log/slog" "math" "net" "slices" @@ -621,7 +622,9 @@ func (repo *MoneroRepo) ProcessJob(report ProbeReport, proberId int64) error { WHERE node_id = ? AND date_checked > ?` - repo.db.Get(&nodeStats, qstats, report.NodeInfo.ID, limitTs) + if err := repo.db.Get(&nodeStats, qstats, report.NodeInfo.ID, limitTs); err != nil { + slog.Warn(err.Error()) + } avgUptime := (float64(nodeStats.OnlineCount) / float64(nodeStats.TotalFetched)) * 100 report.NodeInfo.Uptime = math.Ceil(avgUptime*100) / 100 @@ -684,7 +687,7 @@ func (repo *MoneroRepo) ProcessJob(report ProbeReport, proberId int64) error { cors_capable = ? WHERE id = ?` - _, err = repo.db.Exec(update, + _, err := repo.db.Exec(update, nodeAvailable, report.NodeInfo.Nettype, report.NodeInfo.Height, @@ -704,8 +707,11 @@ func (repo *MoneroRepo) ProcessJob(report ProbeReport, proberId int64) error { string(statuesValueToDb), report.NodeInfo.CORSCapable, report.NodeInfo.ID) + if err != nil { + slog.Warn(err.Error()) + } } else { - update := ` + u := ` UPDATE tbl_node SET is_available = ?, @@ -714,15 +720,19 @@ func (repo *MoneroRepo) ProcessJob(report ProbeReport, proberId int64) error { last_check_status = ? WHERE id = ?` - _, err = repo.db.Exec(update, nodeAvailable, report.NodeInfo.Uptime, now.Unix(), string(statuesValueToDb), report.NodeInfo.ID) + if _, err := repo.db.Exec(u, nodeAvailable, report.NodeInfo.Uptime, now.Unix(), string(statuesValueToDb), report.NodeInfo.ID); err != nil { + slog.Warn(err.Error()) + } } if avgUptime <= 0 && nodeStats.TotalFetched > 300 { fmt.Println("Deleting Monero node (0% uptime from > 300 records)") - repo.Delete(report.NodeInfo.ID) + if err := repo.Delete(report.NodeInfo.ID); err != nil { + slog.Warn(err.Error()) + } } - repo.db.Exec(` + _, err = repo.db.Exec(` UPDATE tbl_prober SET last_submit_ts = ? WHERE id = ?`, now.Unix(), proberId)