Skip to content

Commit

Permalink
add error handling for StringSlice
Browse files Browse the repository at this point in the history
  • Loading branch information
evandam committed Sep 6, 2023
1 parent 3fe3cc8 commit 37490f2
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions cmd/commandfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,19 @@ func cmdRun(fl Flags) (int, error) {
runCmdConfigFlag := fl.String("config")
runCmdConfigAdapterFlag := fl.String("adapter")
runCmdResumeFlag := fl.Bool("resume")
runCmdLoadEnvfileFlag, _ := fl.GetStringSlice("envfile")
runCmdPrintEnvFlag := fl.Bool("environ")
runCmdWatchFlag := fl.Bool("watch")
runCmdPidfileFlag := fl.String("pidfile")
runCmdPingbackFlag := fl.String("pingback")

var err error
var runCmdLoadEnvfileFlag []string
runCmdLoadEnvfileFlag, err = fl.GetStringSlice("envfile")
if err != nil {
return caddy.ExitCodeFailedStartup,
fmt.Errorf("reading envfile flag: %v", err)
}

// load all additional envs as soon as possible
for _, envFile := range runCmdLoadEnvfileFlag {
if err := loadEnvFromFile(envFile); err != nil {
Expand All @@ -181,7 +188,6 @@ func cmdRun(fl Flags) (int, error) {

// load the config, depending on flags
var config []byte
var err error
if runCmdResumeFlag {
config, err = os.ReadFile(caddy.ConfigAutosavePath)
if os.IsNotExist(err) {
Expand Down Expand Up @@ -497,7 +503,14 @@ func cmdAdaptConfig(fl Flags) (int, error) {
func cmdValidateConfig(fl Flags) (int, error) {
validateCmdConfigFlag := fl.String("config")
validateCmdAdapterFlag := fl.String("adapter")
runCmdLoadEnvfileFlag, _ := fl.GetStringSlice("envfile")

var err error
var runCmdLoadEnvfileFlag []string
runCmdLoadEnvfileFlag, err = fl.GetStringSlice("envfile")
if err != nil {
return caddy.ExitCodeFailedStartup,
fmt.Errorf("reading envfile flag: %v", err)
}

// load all additional envs as soon as possible
for _, envFile := range runCmdLoadEnvfileFlag {
Expand All @@ -508,7 +521,6 @@ func cmdValidateConfig(fl Flags) (int, error) {
}

// use default config and ensure a config file is specified
var err error
validateCmdConfigFlag, err = configFileWithRespectToDefault(caddy.Log(), validateCmdConfigFlag)
if err != nil {
return caddy.ExitCodeFailedStartup, err
Expand Down

0 comments on commit 37490f2

Please sign in to comment.