mirror of
https://github.com/rclone/rclone.git
synced 2025-01-03 04:49:47 +01:00
config: remove log.Fatal from loading config file #5234
This commit is contained in:
parent
2fe4fe2766
commit
661fa5786d
@ -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")
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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")
|
||||
|
@ -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(), "")
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user