diff --git a/backend/alias/alias_internal_test.go b/backend/alias/alias_internal_test.go index 8b4efa2ec..35d58f8f1 100644 --- a/backend/alias/alias_internal_test.go +++ b/backend/alias/alias_internal_test.go @@ -20,7 +20,7 @@ var ( ) func prepare(t *testing.T, root string) { - configfile.LoadConfig(context.Background()) + require.NoError(t, configfile.LoadConfig(context.Background())) // Configure the remote config.FileSet(remoteName, "type", "alias") diff --git a/backend/http/http_internal_test.go b/backend/http/http_internal_test.go index 43e78444e..cd334e5c9 100644 --- a/backend/http/http_internal_test.go +++ b/backend/http/http_internal_test.go @@ -47,7 +47,7 @@ func prepareServer(t *testing.T) (configmap.Simple, func()) { ts := httptest.NewServer(handler) // Configure the remote - configfile.LoadConfig(context.Background()) + require.NoError(t, configfile.LoadConfig(context.Background())) // fs.Config.LogLevel = fs.LogLevelDebug // fs.Config.DumpHeaders = true // fs.Config.DumpBodies = true diff --git a/cmd/cmd.go b/cmd/cmd.go index 4d0c053b7..565c6a73e 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -400,7 +400,10 @@ func initConfig() { configflags.SetFlags(ci) // Load the config - configfile.LoadConfig(ctx) + err := configfile.LoadConfig(ctx) + if err != nil { + log.Fatalf("Failed to load config: %v", err) + } // Start accounting accounting.Start(ctx) @@ -411,7 +414,7 @@ func initConfig() { } // Load filters - err := filterflags.Reload(ctx) + err = filterflags.Reload(ctx) if err != nil { log.Fatalf("Failed to load filters: %v", err) } diff --git a/cmd/mountlib/rc_test.go b/cmd/mountlib/rc_test.go index 22c354bc5..70a8d77c2 100644 --- a/cmd/mountlib/rc_test.go +++ b/cmd/mountlib/rc_test.go @@ -21,7 +21,7 @@ import ( func TestRc(t *testing.T) { ctx := context.Background() - configfile.LoadConfig(ctx) + require.NoError(t, configfile.LoadConfig(ctx)) mount := rc.Calls.Get("mount/mount") assert.NotNil(t, mount) unmount := rc.Calls.Get("mount/unmount") diff --git a/cmd/serve/dlna/dlna_test.go b/cmd/serve/dlna/dlna_test.go index 535c85f26..459d13715 100644 --- a/cmd/serve/dlna/dlna_test.go +++ b/cmd/serve/dlna/dlna_test.go @@ -41,7 +41,7 @@ func startServer(t *testing.T, f fs.Fs) { } func TestInit(t *testing.T) { - configfile.LoadConfig(context.Background()) + require.NoError(t, configfile.LoadConfig(context.Background())) f, err := fs.NewFs(context.Background(), "testdata/files") l, _ := f.List(context.Background(), "") diff --git a/cmd/serve/http/http_test.go b/cmd/serve/http/http_test.go index cec0bd36b..a88d25482 100644 --- a/cmd/serve/http/http_test.go +++ b/cmd/serve/http/http_test.go @@ -61,7 +61,7 @@ var ( func TestInit(t *testing.T) { ctx := context.Background() // Configure the remote - configfile.LoadConfig(context.Background()) + require.NoError(t, configfile.LoadConfig(context.Background())) // fs.Config.LogLevel = fs.LogLevelDebug // fs.Config.DumpHeaders = true // fs.Config.DumpBodies = true diff --git a/cmd/serve/restic/restic_appendonly_test.go b/cmd/serve/restic/restic_appendonly_test.go index 74b1ec1d3..56923aa97 100644 --- a/cmd/serve/restic/restic_appendonly_test.go +++ b/cmd/serve/restic/restic_appendonly_test.go @@ -66,7 +66,7 @@ func createOverwriteDeleteSeq(t testing.TB, path string) []TestRequest { // TestResticHandler runs tests on the restic handler code, especially in append-only mode. func TestResticHandler(t *testing.T) { ctx := context.Background() - configfile.LoadConfig(ctx) + require.NoError(t, configfile.LoadConfig(ctx)) buf := make([]byte, 32) _, err := io.ReadFull(rand.Reader, buf) require.NoError(t, err) diff --git a/fs/config/config.go b/fs/config/config.go index b21f369bf..524c337b9 100644 --- a/fs/config/config.go +++ b/fs/config/config.go @@ -5,7 +5,6 @@ import ( "context" "encoding/json" "fmt" - "log" mathrand "math/rand" "os" "path/filepath" @@ -328,7 +327,7 @@ func SetConfigPath(path string) (err error) { } // LoadConfig loads the config file -func LoadConfig(ctx context.Context) { +func LoadConfig(ctx context.Context) error { // Set RCLONE_CONFIG_DIR for backend config and subprocesses // If empty configPath (in-memory only) the value will be "." _ = os.Setenv("RCLONE_CONFIG_DIR", filepath.Dir(configPath)) @@ -340,10 +339,12 @@ func LoadConfig(ctx context.Context) { fs.Logf(nil, "Config file %q not found - using defaults", configPath) } } else if err != nil { - log.Fatalf("Failed to load config file %q: %v", configPath, err) + fs.Errorf(nil, "Failed to load config file %q: %v", configPath, err) + return errors.Wrap(err, "failed to load config file") } else { fs.Debugf(nil, "Using config file from %q", configPath) } + return nil } // ErrorConfigFileNotFound is returned when the config file is not found diff --git a/fs/config/config_test.go b/fs/config/config_test.go index 1fff9ef60..40127d555 100644 --- a/fs/config/config_test.go +++ b/fs/config/config_test.go @@ -9,6 +9,7 @@ import ( "github.com/rclone/rclone/fs/config" "github.com/rclone/rclone/fs/config/configfile" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestConfigLoad(t *testing.T) { @@ -18,7 +19,7 @@ func TestConfigLoad(t *testing.T) { assert.NoError(t, config.SetConfigPath(oldConfigPath)) }() config.ClearConfigPassword() - configfile.LoadConfig(context.Background()) + require.NoError(t, configfile.LoadConfig(context.Background())) sections := config.Data.GetSectionList() var expect = []string{"RCLONE_ENCRYPT_V0", "nounc", "unc"} assert.Equal(t, expect, sections) diff --git a/fs/config/configfile/configfile.go b/fs/config/configfile/configfile.go index 969921fde..e2dd06ee2 100644 --- a/fs/config/configfile/configfile.go +++ b/fs/config/configfile/configfile.go @@ -16,9 +16,9 @@ import ( ) // LoadConfig installs the config file handler and calls config.LoadConfig -func LoadConfig(ctx context.Context) { +func LoadConfig(ctx context.Context) error { config.Data = &Storage{} - config.LoadConfig(ctx) + return config.LoadConfig(ctx) } // Storage implements config.Storage for saving and loading config diff --git a/fs/config/rc_test.go b/fs/config/rc_test.go index 89d3bb9e9..1de051f28 100644 --- a/fs/config/rc_test.go +++ b/fs/config/rc_test.go @@ -18,7 +18,7 @@ const testName = "configTestNameForRc" func TestRc(t *testing.T) { ctx := context.Background() - configfile.LoadConfig(ctx) + require.NoError(t, configfile.LoadConfig(ctx)) // Create the test remote call := rc.Calls.Get("config/create") assert.NotNil(t, call) diff --git a/fs/config/ui_test.go b/fs/config/ui_test.go index ed49977f1..cd87d9813 100644 --- a/fs/config/ui_test.go +++ b/fs/config/ui_test.go @@ -43,7 +43,7 @@ func testConfigFile(t *testing.T, configFileName string) func() { assert.NoError(t, config.SetConfigPath(path)) ci = &fs.ConfigInfo{} - configfile.LoadConfig(ctx) + require.NoError(t, configfile.LoadConfig(ctx)) assert.Equal(t, []string{}, config.Data.GetSectionList()) // Fake a remote diff --git a/fs/rc/rcserver/rcserver_test.go b/fs/rc/rcserver/rcserver_test.go index b17f3dd0b..e203ec464 100644 --- a/fs/rc/rcserver/rcserver_test.go +++ b/fs/rc/rcserver/rcserver_test.go @@ -103,7 +103,7 @@ type testRun struct { // Run a suite of tests func testServer(t *testing.T, tests []testRun, opt *rc.Options) { ctx := context.Background() - configfile.LoadConfig(ctx) + require.NoError(t, configfile.LoadConfig(ctx)) mux := http.NewServeMux() opt.HTTPOptions.Template = testTemplate rcServer := newServer(ctx, opt, mux) diff --git a/fstest/fstest.go b/fstest/fstest.go index 7ff4f20a4..fcb8ae4b9 100644 --- a/fstest/fstest.go +++ b/fstest/fstest.go @@ -71,7 +71,10 @@ func Initialise() { if envConfig := os.Getenv("RCLONE_CONFIG"); envConfig != "" { _ = config.SetConfigPath(envConfig) } - configfile.LoadConfig(ctx) + err := configfile.LoadConfig(ctx) + if err != nil { + log.Fatalf("Initialise failed to load config: %v", err) + } accounting.Start(ctx) if *Verbose { ci.LogLevel = fs.LogLevelDebug diff --git a/fstest/test_all/test_all.go b/fstest/test_all/test_all.go index a6703b504..3a3965c97 100644 --- a/fstest/test_all/test_all.go +++ b/fstest/test_all/test_all.go @@ -72,7 +72,10 @@ func main() { log.Println("test_all should be run from the root of the rclone source code") log.Fatal(err) } - configfile.LoadConfig(context.Background()) + err = configfile.LoadConfig(context.Background()) + if err != nil { + log.Fatalf("Failed to load config: %v", err) + } // Seed the random number generator rand.Seed(time.Now().UTC().UnixNano())