Skip to content

Commit

Permalink
Addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
urvisavla committed Jul 10, 2023
1 parent 52918fc commit 3b6aa7a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 12 additions & 9 deletions services/horizon/internal/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
apkg "github.com/stellar/go/support/app"
support "github.com/stellar/go/support/config"
"github.com/stellar/go/support/db"
"github.com/stellar/go/support/errors"
"github.com/stellar/go/support/log"
"github.com/stellar/throttled"
)
Expand Down Expand Up @@ -575,14 +576,16 @@ func Flags() (*Config, support.ConfigOptions) {
CustomSetValue: func(co *support.ConfigOption) error {
val := viper.GetString(co.Name)
if val != "" && val != StellarPubnet && val != StellarTestnet {
return fmt.Errorf("invalid network %s. Use 'pubnet' or 'testnet'", val)
return fmt.Errorf("invalid network %s. Use '%s' or '%s'",
val, StellarPubnet, StellarTestnet)
}
*co.ConfigKey.(*string) = val
return nil
},
Usage: fmt.Sprintf("stellar public network, either 'testnet' or 'pubnet'."+
Usage: fmt.Sprintf("stellar public network, either '%s' or '%s'."+
" It automatically configures network settings, including %s, %s, and %s.",
NetworkPassphraseFlagName, HistoryArchiveURLsFlagName, CaptiveCoreConfigPathName),
StellarPubnet, StellarTestnet, NetworkPassphraseFlagName,
HistoryArchiveURLsFlagName, CaptiveCoreConfigPathName),
},
}

Expand Down Expand Up @@ -662,7 +665,7 @@ func loadDefaultCaptiveCoreToml(config *Config, defaultConfigData []byte) error
var err error
config.CaptiveCoreToml, err = ledgerbackend.NewCaptiveCoreTomlFromData(defaultConfigData, config.CaptiveCoreTomlParams)
if err != nil {
return fmt.Errorf("invalid captive core toml: %v", err)
return errors.Wrap(err, "invalid captive core toml")
}
return nil
}
Expand All @@ -677,7 +680,7 @@ func loadCaptiveCoreTomlFromFile(config *Config) error {

config.CaptiveCoreToml, err = ledgerbackend.NewCaptiveCoreTomlFromFile(config.CaptiveCoreConfigPath, config.CaptiveCoreTomlParams)
if err != nil {
return fmt.Errorf("invalid captive core toml file: %v", err)
return errors.Wrap(err, "invalid captive core toml file")
}
return nil
}
Expand Down Expand Up @@ -731,7 +734,7 @@ func createCaptiveCoreConfig(config *Config) error {
var err error
config.CaptiveCoreToml, err = ledgerbackend.NewCaptiveCoreToml(config.CaptiveCoreTomlParams)
if err != nil {
return fmt.Errorf("invalid captive core toml file %v", err)
return errors.Wrap(err, "invalid captive core toml file")
}
}

Expand All @@ -754,12 +757,12 @@ func setCaptiveCoreConfiguration(config *Config) error {
if config.Network != "" {
err := createCaptiveCoreDefaultConfig(config)
if err != nil {
return fmt.Errorf("error generating default captive core config. %v", err)
return errors.Wrap(err, "error generating default captive core config.")
}
} else {
err := createCaptiveCoreConfig(config)
if err != nil {
return fmt.Errorf("error generating captive core config. %v", err)
return errors.Wrap(err, "error generating captive core config.")
}
}

Expand Down Expand Up @@ -809,7 +812,7 @@ func ApplyFlags(config *Config, flags support.ConfigOptions, options ApplyOption
if config.EnableCaptiveCoreIngestion {
err := setCaptiveCoreConfiguration(config)
if err != nil {
return fmt.Errorf("error generating captive core configuration. %v", err)
return errors.Wrap(err, "error generating captive core configuration")
}
}
} else {
Expand Down
2 changes: 2 additions & 0 deletions services/horizon/internal/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func Test_createCaptiveCoreDefaultConfig(t *testing.T) {
Expand Down Expand Up @@ -124,6 +125,7 @@ func Test_createCaptiveCoreConfig(t *testing.T) {
assert.Equal(t, tt.networkPassphrase, tt.config.NetworkPassphrase)
assert.Equal(t, tt.historyArchiveURLs, tt.config.HistoryArchiveURLs)
} else {
require.Error(t, e)
assert.Equal(t, tt.errStr, e.Error())
}
})
Expand Down

0 comments on commit 3b6aa7a

Please sign in to comment.