Skip to content

Commit

Permalink
print proper errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dvovk committed May 28, 2024
1 parent 26761dd commit 2205dcc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
3 changes: 2 additions & 1 deletion cmd/diag/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ var Command = cli.Command{
func startPrintDBsInfo(cliCtx *cli.Context) error {
data, err := DBsInfo(cliCtx)
if err != nil {
return err
util.RenderError(err)
return nil
}

dbToPrint := cliCtx.String(DBNameFlag.Name)
Expand Down
9 changes: 4 additions & 5 deletions cmd/diag/downloader/diag_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func printDownloadStatus(cliCtx *cli.Context) error {
data, err := getData(cliCtx)

if err != nil {

return err
util.RenderError(err)
return nil
}

snapshotDownloadStatus := getSnapshotStatusRow(data.SnapshotDownload)
Expand Down Expand Up @@ -92,9 +92,8 @@ func printFiles(cliCtx *cli.Context) error {
data, err := getData(cliCtx)

if err != nil {
txt := text.Colors{text.FgWhite, text.BgRed}
fmt.Printf("%s %s", txt.Sprint("[ERROR]"), "Failed to connect to Erigon node.")
return err
util.RenderError(err)
return nil
}

snapshotDownloadStatus := getSnapshotStatusRow(data.SnapshotDownload)
Expand Down
3 changes: 2 additions & 1 deletion cmd/diag/stages/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func printCurentStage(cliCtx *cli.Context) error {

err := util.MakeHttpGetCall(cliCtx.Context, url, &data)
if err != nil {
return err
util.RenderError(err)
return nil
}

stagesRows := getStagesRows(data.SyncStages)
Expand Down
13 changes: 13 additions & 0 deletions cmd/diag/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"net/http"
"os"
"strings"
"time"

"github.com/jedib0t/go-pretty/v6/table"
Expand All @@ -25,6 +26,9 @@ func MakeHttpGetCall(ctx context.Context, url string, data interface{}) error {

resp, err := client.Do(req)
if err != nil {
if strings.Contains(err.Error(), "connection refused") {
return fmt.Errorf("looks like Erigon node is not running or it running or you specified wrong diagnostics URL \n if you run Erigon node with specifying '--diagnostics.endpoint.addr' or '--diagnostics.endpoint.port' falgs you must specify '--debug.addr' flag with the same address and port")
}
return err
}

Expand All @@ -36,6 +40,10 @@ func MakeHttpGetCall(ctx context.Context, url string, data interface{}) error {

err = json.Unmarshal(body, &data)
if err != nil {
if err.Error() == "invalid character 'p' after top-level value" {
return fmt.Errorf("diagnostics not initialized yet, try again in a few seconds")
}

return err
}

Expand Down Expand Up @@ -94,3 +102,8 @@ func RenderUseDiagUI() {
txt := text.Colors{text.BgGreen, text.Bold}
fmt.Println(txt.Sprint("To get detailed info about Erigon node state use 'diag ui' command."))
}

func RenderError(err error) {
txt := text.Colors{text.FgWhite, text.BgRed}
fmt.Printf("%s %s", txt.Sprint("[ERROR]"), err)
}

0 comments on commit 2205dcc

Please sign in to comment.