Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diagnostics: print understandable error #10527

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("it looks like the Erigon node is not running, is running incorrectly, or you have specified the wrong diagnostics URL. If you run the Erigon node with the '--diagnostics.endpoint.addr' or '--diagnostics.endpoint.port' flags, you must also specify the '--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 have not been initialized yet. Please 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)
}
Loading