Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
return error instead of panic
Browse files Browse the repository at this point in the history
  • Loading branch information
facs95 committed Aug 29, 2022
1 parent 2421c38 commit c5acf65
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
5 changes: 4 additions & 1 deletion rpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ func NewBackend(
panic(err)
}

appConf := config.GetConfig(ctx.Viper)
appConf, err := config.GetConfig(ctx.Viper)
if err != nil {
panic(err)
}

algos, _ := clientCtx.Keyring.SupportedAlgorithms()
if !algos.Contains(hd.EthSecp256k1) {
Expand Down
6 changes: 5 additions & 1 deletion rpc/backend/node_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ func (b *Backend) NewMnemonic(uid string, language keyring.Language, hdPath, bip
// NOTE: this function accepts only integers to have the same interface than go-eth
// to use float values, the gas prices must be configured using the configuration file
func (b *Backend) SetGasPrice(gasPrice hexutil.Big) bool {
appConf := config.GetConfig(b.clientCtx.Viper)
appConf, err := config.GetConfig(b.clientCtx.Viper)
if err != nil {
b.logger.Debug("could not get the server config", "error", err.Error())
return false
}

var unit string
minGasPrices := appConf.GetMinGasPrices()
Expand Down
6 changes: 3 additions & 3 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ func (c TLSConfig) Validate() error {
}

// GetConfig returns a fully parsed Config object.
func GetConfig(v *viper.Viper) Config {
func GetConfig(v *viper.Viper) (Config, error) {
cfg, err := config.GetConfig(v)
if err != nil {
panic(err)
return Config{}, err
}

return Config{
Expand Down Expand Up @@ -324,7 +324,7 @@ func GetConfig(v *viper.Viper) Config {
CertificatePath: v.GetString("tls.certificate-path"),
KeyPath: v.GetString("tls.key-path"),
},
}
}, nil
}

// ParseConfig retrieves the default environment configuration for the
Expand Down
5 changes: 4 additions & 1 deletion server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator ty
return err
}

config := config.GetConfig(ctx.Viper)
config, err := config.GetConfig(ctx.Viper)
if err != nil {
return err
}

if err := config.ValidateBasic(); err != nil {
if strings.Contains(err.Error(), "set min gas price in app.toml or flag or env variable") {
Expand Down

0 comments on commit c5acf65

Please sign in to comment.