From fdbdfed30f9be8108a0a2c3e38ce6523f1a4699c Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 13 Oct 2022 15:46:59 -0700 Subject: [PATCH] fix: proper error when parsing telemetry configuration (backport #12981) (#12999) (#348) (#349) Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit 9fed068438a87b390b2f741404ea1f044ae6998b) Co-authored-by: Roman --- server/config/config.go | 17 ++++++++++++----- server/start.go | 5 ++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/server/config/config.go b/server/config/config.go index 0a4850a64ab0..41ebe524bbd0 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -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)}) } @@ -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. diff --git a/server/start.go b/server/start.go index e3b7119f5b5e..aeae9d47e32b 100644 --- a/server/start.go +++ b/server/start.go @@ -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 " +