fix: return error from function LoadConfigFile to the caller

Signed-off-by: wuwenjia5 <wuwenjia5@jd.com>
This commit is contained in:
wuwenjia5 2019-10-08 17:49:46 +08:00 committed by awzhgw
parent 4e573923f5
commit c8b46cc021
4 changed files with 19 additions and 7 deletions

View File

@ -89,7 +89,11 @@ func main() {
* LoadConfigFile should be checked before start daemon, since it will
* call os.Exit() w/o notifying the parent process.
*/
cfg := config.LoadConfigFile(*configFile)
cfg, err := config.LoadConfigFile(*configFile)
if err != nil {
daemonize.SignalOutcome(err)
os.Exit(1)
}
if !*configForeground {
if err := startDaemon(); err != nil {

View File

@ -90,7 +90,11 @@ func main() {
* LoadConfigFile should be checked before start daemon, since it will
* call os.Exit() w/o notifying the parent process.
*/
cfg := config.LoadConfigFile(*configFile)
cfg, err := config.LoadConfigFile(*configFile)
if err != nil {
daemonize.SignalOutcome(err)
os.Exit(1)
}
if !*configForeground {
if err := startDaemon(); err != nil {

View File

@ -127,7 +127,11 @@ func main() {
* LoadConfigFile should be checked before start daemon, since it will
* call os.Exit() w/o notifying the parent process.
*/
cfg := config.LoadConfigFile(*configFile)
cfg, err := config.LoadConfigFile(*configFile)
if err != nil {
daemonize.SignalOutcome(err)
os.Exit(1)
}
if !*configForeground {
if err := startDaemon(); err != nil {
@ -185,7 +189,7 @@ func main() {
level = log.ErrorLevel
}
_, err := log.InitLog(logDir, module, level, nil)
_, err = log.InitLog(logDir, module, level, nil)
if err != nil {
daemonize.SignalOutcome(fmt.Errorf("Fatal: failed to init log - %v", err))
os.Exit(1)

View File

@ -34,13 +34,13 @@ func newConfig() *Config {
}
// LoadConfigFile loads config information from a JSON file.
func LoadConfigFile(filename string) *Config {
func LoadConfigFile(filename string) (*Config, error) {
result := newConfig()
err := result.parse(filename)
if err != nil {
log.Fatalf("error loading config file %s: %s", filename, err)
log.Printf("error loading config file %s: %s", filename, err)
}
return result
return result, err
}
// LoadConfigString loads config information from a JSON string.