Skip to content
Snippets Groups Projects
Unverified Commit 903a2488 authored by Benjamin Bollen's avatar Benjamin Bollen
Browse files

Better shield subtree extraction from configuration to avoid Viper panic

parent 716f28eb
No related branches found
No related tags found
No related merge requests found
......@@ -144,7 +144,13 @@ func (tmintConfig *TendermintConfig) GetMapString(key string) map[string]string
}
func (tmintConfig *TendermintConfig) GetConfig(key string) tendermintConfig.Config {
return &TendermintConfig {
// TODO: [ben] log out a warning as this indicates a potentially breaking code
// change from Tendermints side
if !tmintConfig.subTree.IsSet(key) {
return &TendermintConfig {
subTree: viper.New(),
}}
return &TendermintConfig {
subTree: tmintConfig.subTree.Sub(key),
}
}
......
......@@ -62,6 +62,9 @@ func NewTendermintNode(moduleConfig *config.ModuleConfig,
// to be written in tendermint's root directory.
// NOTE: [ben] as elsewhere Sub panics if config file does not have this
// subtree. To shield in go-routine, or PR to viper.
if !moduleConfig.Config.IsSet("confighuration") {
return nil, fmt.Errorf("Failed to extract Tendermint configuration subtree.")
}
tendermintConfigViper := moduleConfig.Config.Sub("configuration")
if tendermintConfigViper == nil {
return nil,
......
......@@ -71,6 +71,10 @@ func loadModuleConfig(do *definitions.Do, module string) (*config.ModuleConfig,
// TODO: [ben] Viper internally panics if `moduleName` contains an unallowed
// character (eg, a dash). Either this needs to be wrapped in a go-routine
// and recovered from or a PR to viper is needed to address this bug.
if !do.Config.IsSet(moduleName) {
return nil, fmt.Errorf("Failed to read configuration section for %s",
moduleName)
}
subConfig := do.Config.Sub(moduleName)
if subConfig == nil {
return nil,
......@@ -93,7 +97,10 @@ func loadModuleConfig(do *definitions.Do, module string) (*config.ModuleConfig,
// LoadServerModuleConfig wraps specifically for the servers run by core
func LoadServerConfig(do *definitions.Do) (*server.ServerConfig, error) {
// load configuration subtree for servers
subConfig := do.Config.Sub("servers")
if !do.Config.IsSet("servers") {
return nil, fmt.Errorf("Failed to read configuration section for servers")
}
subConfig := do.Config.Sub("servers")
if subConfig == nil {
return nil,
fmt.Errorf("Failed to read configuration section for servers")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment