Skip to content

Commit

Permalink
Merge pull request #508 from twhiston/cfg_file_error_scope
Browse files Browse the repository at this point in the history
bugfix for error scopes in config checking
  • Loading branch information
twhiston committed Mar 27, 2018
2 parents 8bb45c2 + 0316fbc commit b24b22b
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,30 +157,19 @@ func loadConfig(){
//If the confPath option has been set try to load and decode it
if confPath != nil && len(*confPath) > 0 {
file, err := os.Open(*confPath)
if err != nil {
panic(err)
}
exitOnConfigError(err)
decodeConfig(file)
} else {

// if no confPath look in the cwd
cwd, err := os.Getwd()
exitOnConfigError(err)
cwd = cwd+"/config.json"
confPath = &cwd
if err == nil {
file, err := os.Open(*confPath)
if err == nil {
decodeConfig(file)
}
}
if err != nil {
fmt.Println("Cannot Find configuration! Use -c parameter to point to a JSON file generated by -setup.\n\n Hint: have you run `-setup` ?")
os.Exit(1)
}

file, err := os.Open(*confPath)
exitOnConfigError(err)
decodeConfig(file)
}
fmt.Println("Using config file: "+ *confPath)

}

func validateConfig(){
Expand Down Expand Up @@ -210,6 +199,13 @@ func validatePort() {
}
}

func exitOnConfigError(err error){
if err != nil {
fmt.Println("Cannot Find configuration! Use -c parameter to point to a JSON file generated by -setup.\n\n Hint: have you run `-setup` ?")
os.Exit(1)
}
}



func decodeConfig(file *os.File){
Expand Down

0 comments on commit b24b22b

Please sign in to comment.