diff --git a/internal/config/config.go b/internal/config/config.go index 8e30142d..e2717ec6 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -734,9 +734,9 @@ func LoadConfig(configDir, configFile string) error { if errors.As(err, &viper.ConfigFileNotFoundError{}) { logger.Debug(logSender, "", "no configuration file found") } else { - // should we return the error and not start here? logger.Warn(logSender, "", "error loading configuration file: %v", err) logger.WarnToConsole("error loading configuration file: %v", err) + return err } } checkOverrideDefaultSettings() diff --git a/internal/config/config_test.go b/internal/config/config_test.go index e0007410..1e6945f7 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -68,11 +68,11 @@ func TestLoadConfigTest(t *testing.T) { confName := tempConfigName + ".json" //nolint:goconst configFilePath := filepath.Join(configDir, confName) err = config.LoadConfig(configDir, confName) - assert.NoError(t, err) + assert.Error(t, err) err = os.WriteFile(configFilePath, []byte("{invalid json}"), os.ModePerm) assert.NoError(t, err) err = config.LoadConfig(configDir, confName) - assert.NoError(t, err) + assert.Error(t, err) err = os.WriteFile(configFilePath, []byte(`{"sftpd": {"max_auth_tries": "a"}}`), os.ModePerm) assert.NoError(t, err) err = config.LoadConfig(configDir, confName) @@ -1587,7 +1587,7 @@ func TestConfigFromEnv(t *testing.T) { os.Unsetenv("SFTPGO_HTTPD__SETUP__INSTALLATION_CODE") os.Unsetenv("SFTPGO_ACME__HTTP01_CHALLENGE_PORT") }) - err := config.LoadConfig(".", "invalid config") + err := config.LoadConfig(configDir, "") assert.NoError(t, err) sftpdConfig := config.GetSFTPDConfig() assert.Equal(t, "127.0.0.1", sftpdConfig.Bindings[0].Address)