Skip to content

Commit

Permalink
FAB-7769 if FABRIC_CFG_PATH invalid, peer panic
Browse files Browse the repository at this point in the history
if FABRIC_CFG_PATH set to non existant directory,
peer panics

Change-Id: Ia162dd7f9c49fcec25005f27a87a839f6fddb75a
Signed-off-by: John D Sheehan <john.d.sheehan@gmail.com>
  • Loading branch information
johndsheehan committed Jan 22, 2018
1 parent ce1f6a4 commit 7d5bc87
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
5 changes: 5 additions & 0 deletions core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ func InitViper(v *viper.Viper, configName string) error {
if altPath != "" {
// If the user has overridden the path with an envvar, its the only path
// we will consider

if !dirExists(altPath) {
return fmt.Errorf("FABRIC_CFG_PATH %s does not exist", altPath)
}

addConfigPath(v, altPath)
} else {
// If we get here, we should use the default paths in priority order:
Expand Down
9 changes: 6 additions & 3 deletions peer/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ func init() {

//InitConfig initializes viper config
func InitConfig(cmdRoot string) error {
config.InitViper(nil, cmdRoot)
err := config.InitViper(nil, cmdRoot)
if err != nil {
return err
}

err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
err = viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
return errors.WithMessage(err, fmt.Sprintf("error when reading %s config file", cmdRoot))
}

Expand Down
11 changes: 6 additions & 5 deletions peer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,18 @@ func main() {
mainFlags.String("logging-level", "", "Default logging level and overrides, see core.yaml for full syntax")
viper.BindPFlag("logging_level", mainFlags.Lookup("logging-level"))

err := common.InitConfig(cmdRoot)
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("Fatal error when initializing %s config : %s\n", cmdRoot, err))
}

mainCmd.AddCommand(version.Cmd())
mainCmd.AddCommand(node.Cmd())
mainCmd.AddCommand(chaincode.Cmd(nil))
mainCmd.AddCommand(clilogging.Cmd(nil))
mainCmd.AddCommand(channel.Cmd(nil))

err := common.InitConfig(cmdRoot)
if err != nil { // Handle errors reading the config file
logger.Errorf("Fatal error when initializing %s config : %s", cmdRoot, err)
os.Exit(1)
}

runtime.GOMAXPROCS(viper.GetInt("peer.gomaxprocs"))

// setup system-wide logging backend based on settings from core.yaml
Expand Down

0 comments on commit 7d5bc87

Please sign in to comment.