Skip to content

Commit 7d5bc87

Browse files
committed
FAB-7769 if FABRIC_CFG_PATH invalid, peer panic
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>
1 parent ce1f6a4 commit 7d5bc87

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

core/config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ func InitViper(v *viper.Viper, configName string) error {
140140
if altPath != "" {
141141
// If the user has overridden the path with an envvar, its the only path
142142
// we will consider
143+
144+
if !dirExists(altPath) {
145+
return fmt.Errorf("FABRIC_CFG_PATH %s does not exist", altPath)
146+
}
147+
143148
addConfigPath(v, altPath)
144149
} else {
145150
// If we get here, we should use the default paths in priority order:

peer/common/common.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,13 @@ func init() {
7070

7171
//InitConfig initializes viper config
7272
func InitConfig(cmdRoot string) error {
73-
config.InitViper(nil, cmdRoot)
73+
err := config.InitViper(nil, cmdRoot)
74+
if err != nil {
75+
return err
76+
}
7477

75-
err := viper.ReadInConfig() // Find and read the config file
76-
if err != nil { // Handle errors reading the config file
78+
err = viper.ReadInConfig() // Find and read the config file
79+
if err != nil { // Handle errors reading the config file
7780
return errors.WithMessage(err, fmt.Sprintf("error when reading %s config file", cmdRoot))
7881
}
7982

peer/main.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,18 @@ func main() {
7272
mainFlags.String("logging-level", "", "Default logging level and overrides, see core.yaml for full syntax")
7373
viper.BindPFlag("logging_level", mainFlags.Lookup("logging-level"))
7474

75-
err := common.InitConfig(cmdRoot)
76-
if err != nil { // Handle errors reading the config file
77-
panic(fmt.Errorf("Fatal error when initializing %s config : %s\n", cmdRoot, err))
78-
}
79-
8075
mainCmd.AddCommand(version.Cmd())
8176
mainCmd.AddCommand(node.Cmd())
8277
mainCmd.AddCommand(chaincode.Cmd(nil))
8378
mainCmd.AddCommand(clilogging.Cmd(nil))
8479
mainCmd.AddCommand(channel.Cmd(nil))
8580

81+
err := common.InitConfig(cmdRoot)
82+
if err != nil { // Handle errors reading the config file
83+
logger.Errorf("Fatal error when initializing %s config : %s", cmdRoot, err)
84+
os.Exit(1)
85+
}
86+
8687
runtime.GOMAXPROCS(viper.GetInt("peer.gomaxprocs"))
8788

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

0 commit comments

Comments
 (0)