From 8a6098e13ccfc5c9ca0d1869f5f5643859b206cb Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 23 Aug 2022 10:24:17 -0400 Subject: [PATCH] fix: proper error when parsing telemetry configuration (backport #12981) (#12999) --- CHANGELOG.md | 1 + server/config/config.go | 18 ++++++++++++------ server/start.go | 6 +++++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f7af2454059..caddf2fe9d98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* [#12981](https://github.com/cosmos/cosmos-sdk/pull/12981) Return proper error when parsing telemetry configuration. * [#12886](https://github.com/cosmos/cosmos-sdk/pull/12886) Amortize cost of processing cache KV store. * [#12970](https://github.com/cosmos/cosmos-sdk/pull/12970) Bump Tendermint to `v0.34.21` and IAVL to `v0.19.1`. * [#12693](https://github.com/cosmos/cosmos-sdk/pull/12693) Make sure the order of each node is consistent when emitting proto events. diff --git a/server/config/config.go b/server/config/config.go index 6611476a8129..a2ad3bf67e94 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -249,11 +249,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)}) } @@ -313,8 +320,7 @@ func GetConfig(v *viper.Viper) Config { SnapshotInterval: v.GetUint64("state-sync.snapshot-interval"), SnapshotKeepRecent: v.GetUint32("state-sync.snapshot-keep-recent"), }, - } - return *conf, nil + }, 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 0c03cd737bd3..efba2ca7d815 100644 --- a/server/start.go +++ b/server/start.go @@ -331,7 +331,11 @@ func startInProcess[T types.Application](svrCtx *Context, svrCfg serverconfig.Co return err } - config := config.GetConfig(ctx.Viper) + config, err := config.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 " +