lint: No err check

This commit is contained in:
ditatompel 2024-05-24 05:37:27 +07:00
parent 062e0e90b1
commit c25e9224b6
No known key found for this signature in database
GPG key ID: 31D3D06D77950979
4 changed files with 39 additions and 14 deletions

View file

@ -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

View file

@ -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)
}
},
}

View file

@ -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
}

View file

@ -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)