Skip to content

Commit

Permalink
refactor: Fix casing inconsistencies in error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mattevans committed Dec 18, 2024
1 parent 9d8291e commit 8d2d7ce
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 34 deletions.
17 changes: 10 additions & 7 deletions cmd/cli/commands/config/config_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,21 @@ func (p *NetworkConfigPage) initPage() {
func validateBeaconNode(address string) error {
// Check if URL is valid
if !strings.HasPrefix(address, "http://") && !strings.HasPrefix(address, "https://") {
return fmt.Errorf("Beacon node address must start with http:// or https://")
return fmt.Errorf("beacon node address must start with http:// or https://")
}

// Try to connect to the beacon node
client := &http.Client{
Timeout: 5 * time.Second,
}
client := &http.Client{Timeout: 5 * time.Second}

resp, err := client.Get(fmt.Sprintf("%s/eth/v1/node/health", address))
if err != nil {
return fmt.Errorf("We're unable to connect to your beacon node: %w", err)
return fmt.Errorf("we're unable to connect to your beacon node: %w", err)
}

defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("Beacon node returned status %d", resp.StatusCode)
return fmt.Errorf("beacon node returned status %d", resp.StatusCode)
}

return nil
Expand All @@ -181,7 +181,7 @@ func validateBeaconNode(address string) error {
func validateAndUpdate(p *NetworkConfigPage, input *tview.InputField) {
var (
text = input.GetText()
dropdown = p.form.GetFormItem(0).(*tview.DropDown)
dropdown, _ = p.form.GetFormItem(0).(*tview.DropDown)
index, networkOption = dropdown.GetCurrentOption()
)

Expand All @@ -207,14 +207,17 @@ func validateAndUpdate(p *NetworkConfigPage, input *tview.InputField) {
p.display.app.SetFocus(p.form)
},
)

p.display.app.SetRoot(errorModal, true)

return
}

p.display.configService.Update(func(cfg *service.ContributoorConfig) {
if index != -1 {
cfg.NetworkName = networkOption
}

cfg.BeaconNodeAddress = text
})

Expand Down
6 changes: 4 additions & 2 deletions cmd/cli/commands/config/config_output_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (p *OutputServerConfigPage) initPage() {
// Pull together a list of possible output servers and their descriptions.
serverLabels := make([]string, len(tui.AvailableOutputServers))
serverDescriptions := make(map[string]string)

for i, server := range tui.AvailableOutputServers {
serverLabels[i] = server.Label
serverDescriptions[server.Label] = server.Description
Expand Down Expand Up @@ -231,6 +232,7 @@ func validateAndUpdateOutputServer(p *OutputServerConfigPage) {

// Find the corresponding URL
var serverAddress string

for _, server := range tui.AvailableOutputServers {
if server.Label == serverLabel {
serverAddress = server.Value
Expand Down Expand Up @@ -274,8 +276,8 @@ func validateAndUpdateOutputServer(p *OutputServerConfigPage) {

// Get credentials, these are optional for custom servers.
var (
username = p.form.GetFormItem(2).(*tview.InputField)
password = p.form.GetFormItem(3).(*tview.InputField)
username, _ = p.form.GetFormItem(2).(*tview.InputField)
password, _ = p.form.GetFormItem(3).(*tview.InputField)
usernameText = username.GetText()
passwordText = password.GetText()
)
Expand Down
12 changes: 7 additions & 5 deletions cmd/cli/commands/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,24 @@ func installContributoor(c *cli.Context, opts *options.CommandOpts) error {

configService, err := service.NewConfigService(log, c.GlobalString("config-path"))
if err != nil {
return fmt.Errorf("%sError loading config: %v%s", tui.TerminalColorRed, err, tui.TerminalColorReset)
return fmt.Errorf("%serror loading config: %v%s", tui.TerminalColorRed, err, tui.TerminalColorReset)
}

app := tview.NewApplication()
d := NewInstallDisplay(log, app, configService)

// Run the display.
if err := d.Run(); err != nil {
log.Errorf("Error running display: %v", err)
return fmt.Errorf("%sDisplay error: %w%s", tui.TerminalColorRed, err, tui.TerminalColorReset)
log.Errorf("error running display: %v", err)

return fmt.Errorf("%sdisplay error: %w%s", tui.TerminalColorRed, err, tui.TerminalColorReset)
}

// Handle completion.
if err := d.OnComplete(); err != nil {
log.Errorf("Error completing installation: %v", err)
return fmt.Errorf("%sCompletion error: %w%s", tui.TerminalColorRed, err, tui.TerminalColorReset)
log.Errorf("error completing installation: %v", err)

return fmt.Errorf("%scompletion error: %w%s", tui.TerminalColorRed, err, tui.TerminalColorReset)
}

return nil
Expand Down
7 changes: 3 additions & 4 deletions cmd/cli/commands/install/page_10_welcome.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import (

// WelcomePage is the first/introductory page of the install wizard.
type WelcomePage struct {
display *InstallDisplay
page *tui.Page
content tview.Primitive
description *tview.TextView
display *InstallDisplay
page *tui.Page
content tview.Primitive
}

// NewWelcomePage creates a new WelcomePage.
Expand Down
5 changes: 5 additions & 0 deletions cmd/cli/commands/install/page_20_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,20 @@ func (p *NetworkConfigPage) initPage() {
switch event.Key() {
case tcell.KeyDown, tcell.KeyTab:
nextIndex := (index + 1) % len(labels)

descBox.SetText(descriptions[nextIndex])
p.display.app.SetFocus(forms[nextIndex])

return nil
case tcell.KeyUp:
nextIndex := index - 1
if nextIndex < 0 {
nextIndex = len(labels) - 1
}

descBox.SetText(descriptions[nextIndex])
p.display.app.SetFocus(forms[nextIndex])

return nil
case tcell.KeyEsc:
if p.page.Parent != nil {
Expand Down Expand Up @@ -184,5 +188,6 @@ func (p *NetworkConfigPage) initPage() {
// Set initial focus.
p.display.app.SetFocus(forms[0])
descBox.SetText(descriptions[0])

p.content = borderGrid
}
17 changes: 8 additions & 9 deletions cmd/cli/commands/install/page_30_beacon_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ import (

// BeaconNodePage is the page for configuring the users beacon node.
type BeaconNodePage struct {
display *InstallDisplay
page *tui.Page
content tview.Primitive
form *tview.Form
description *tview.TextView
display *InstallDisplay
page *tui.Page
content tview.Primitive
form *tview.Form
}

// NewBeaconNodePage creates a new BeaconNodePage.
Expand Down Expand Up @@ -133,7 +132,7 @@ func (p *BeaconNodePage) initPage() {

func validateAndUpdate(p *BeaconNodePage) {
// Get text from the input field directly
inputField := p.form.GetFormItem(0).(*tview.InputField)
inputField, _ := p.form.GetFormItem(0).(*tview.InputField)
address := inputField.GetText()

// Show loading modal while validating
Expand Down Expand Up @@ -180,13 +179,13 @@ func validateBeaconNode(address string) error {
}

// Try to connect to the beacon node
client := &http.Client{
Timeout: 5 * time.Second,
}
client := &http.Client{Timeout: 5 * time.Second}

resp, err := client.Get(fmt.Sprintf("%s/eth/v1/node/health", address))
if err != nil {
return fmt.Errorf("We're unable to connect to your beacon node: %w", err)
}

defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
Expand Down
2 changes: 2 additions & 0 deletions cmd/cli/commands/install/page_40_output_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func (p *OutputServerPage) initPage() {
for i, server := range tui.AvailableOutputServers {
if server.Label == "Custom" {
defaultIndex = i

break
}
}
Expand All @@ -84,6 +85,7 @@ func (p *OutputServerPage) initPage() {
for i, server := range tui.AvailableOutputServers {
if server.Value == currentAddress {
defaultIndex = i

break
}
}
Expand Down
13 changes: 6 additions & 7 deletions cmd/cli/commands/install/page_50_output_server_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ import (

// OutputServerCredentialsPage is the page for configuring the users output server credentials.
type OutputServerCredentialsPage struct {
display *InstallDisplay
page *tui.Page
content tview.Primitive
form *tview.Form
description *tview.TextView
password string
username string
display *InstallDisplay
page *tui.Page
content tview.Primitive
form *tview.Form
password string
username string
}

// NewOutputServerCredentialsPage creates a new OutputServerCredentialsPage.
Expand Down
2 changes: 2 additions & 0 deletions internal/service/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ func (s *BinaryService) Update() error {
if err != nil || resp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to download checksums: %w", err)
}

defer resp.Body.Close()

// Determine platform and arch
Expand All @@ -211,6 +212,7 @@ func (s *BinaryService) Update() error {
if err != nil || resp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to download binary: %w", err)
}

defer resp.Body.Close()

// Create temp file for download
Expand Down

0 comments on commit 8d2d7ce

Please sign in to comment.