Skip to content

Commit

Permalink
fix: proper error when parsing telemetry configuration (backport cosm…
Browse files Browse the repository at this point in the history
…os#12981) (cosmos#12999) (#348)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 9fed068)
  • Loading branch information
p0mvn authored and mergify[bot] committed Oct 13, 2022
1 parent cd9d50d commit 810e4c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
17 changes: 12 additions & 5 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,18 @@ func DefaultConfig() *Config {
}

// GetConfig returns a fully parsed Config object.
func GetConfig(v *viper.Viper) Config {
globalLabelsRaw := v.Get("telemetry.global-labels").([]interface{})
func GetConfig(v *viper.Viper) (Config, error) {
globalLabelsRaw, ok := v.Get("telemetry.global-labels").([]interface{})
if !ok {
return Config{}, fmt.Errorf("failed to parse global-labels config")
}

globalLabels := make([][]string, 0, len(globalLabelsRaw))
for _, glr := range globalLabelsRaw {
labelsRaw := glr.([]interface{})
for idx, glr := range globalLabelsRaw {
labelsRaw, ok := glr.([]interface{})
if !ok {
return Config{}, fmt.Errorf("failed to parse global label number %d from config", idx)
}
if len(labelsRaw) == 2 {
globalLabels = append(globalLabels, []string{labelsRaw[0].(string), labelsRaw[1].(string)})
}
Expand Down Expand Up @@ -337,7 +344,7 @@ func GetConfig(v *viper.Viper) Config {
SnapshotInterval: v.GetUint64("state-sync.snapshot-interval"),
SnapshotKeepRecent: v.GetUint32("state-sync.snapshot-keep-recent"),
},
}
}, nil
}

// ValidateBasic returns an error if min-gas-prices field is empty in BaseConfig. Otherwise, it returns nil.
Expand Down
5 changes: 4 additions & 1 deletion server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
return err
}

config := serverconfig.GetConfig(ctx.Viper)
config, err := serverconfig.GetConfig(ctx.Viper)
if err != nil {
return err
}
if err := config.ValidateBasic(); err != nil {
ctx.Logger.Error("WARNING: The minimum-gas-prices config in app.toml is set to the empty string. " +
"This defaults to 0 in the current version, but will error in the next version " +
Expand Down

0 comments on commit 810e4c8

Please sign in to comment.