diff --git a/cmd/diag/db/db.go b/cmd/diag/db/db.go index 412902505e2..87a34831397 100644 --- a/cmd/diag/db/db.go +++ b/cmd/diag/db/db.go @@ -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) diff --git a/cmd/diag/downloader/diag_downloader.go b/cmd/diag/downloader/diag_downloader.go index bb213d26def..03f88ee01e9 100644 --- a/cmd/diag/downloader/diag_downloader.go +++ b/cmd/diag/downloader/diag_downloader.go @@ -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) @@ -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) diff --git a/cmd/diag/stages/stages.go b/cmd/diag/stages/stages.go index c9ea3258286..51f453330bb 100644 --- a/cmd/diag/stages/stages.go +++ b/cmd/diag/stages/stages.go @@ -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) diff --git a/cmd/diag/util/util.go b/cmd/diag/util/util.go index 277f7259886..d26eb9a62a8 100644 --- a/cmd/diag/util/util.go +++ b/cmd/diag/util/util.go @@ -7,6 +7,7 @@ import ( "io" "net/http" "os" + "strings" "time" "github.com/jedib0t/go-pretty/v6/table" @@ -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 } @@ -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 } @@ -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) +}