From 19ce0e99a5e5f6992d921be81203101916f640a3 Mon Sep 17 00:00:00 2001 From: Jim Han <50871214+JimhHan@users.noreply.github.com> Date: Wed, 16 Dec 2020 20:35:27 +0800 Subject: [PATCH] Config loader returns error instead of directly panic (#80) --- main/jsonem/jsonem.go | 8 ++++++-- main/run.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/main/jsonem/jsonem.go b/main/jsonem/jsonem.go index cf9227aa..fb4cb5d8 100644 --- a/main/jsonem/jsonem.go +++ b/main/jsonem/jsonem.go @@ -22,9 +22,13 @@ func init() { for i, arg := range v { newError("Reading config: ", arg).AtInfo().WriteToLog() r, err := confloader.LoadConfig(arg) - common.Must(err) + if err != nil { + return nil, newError("failed to read config: ", arg).Base(err) + } c, err := serial.DecodeJSONConfig(r) - common.Must(err) + if err != nil { + return nil, newError("failed to decode config: ", arg).Base(err) + } if i == 0 { // This ensure even if the muti-json parser do not support a setting, // It is still respected automatically for the first configure file diff --git a/main/run.go b/main/run.go index 72bba5d1..3c11ee0c 100644 --- a/main/run.go +++ b/main/run.go @@ -164,7 +164,7 @@ func startXray() (core.Server, error) { config, err := core.LoadConfig(getConfigFormat(), configFiles[0], configFiles) if err != nil { - return nil, newError("failed to read config files: [", configFiles.String(), "]").Base(err) + return nil, newError("failed to load config files: [", configFiles.String(), "]").Base(err) } server, err := core.New(config)