Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

config: remove log.Fatal and replace with error passing where possible

Nick Craig-Wood3cf6ea848b03
diff --git a/cmd/authorize/authorize.go b/cmd/authorize/authorize.go
index d93cdb306..d3114c750 100644
--- a/cmd/authorize/authorize.go
+++ b/cmd/authorize/authorize.go
@@ -29,8 +29,8 @@ rclone config.
Use the --auth-no-open-browser to prevent rclone to open auth
link in default browser automatically.`,
- Run: func(command *cobra.Command, args []string) {
+ RunE: func(command *cobra.Command, args []string) error {
cmd.CheckArgs(1, 3, command, args)
- config.Authorize(context.Background(), args, noAutoBrowser)
+ return config.Authorize(context.Background(), args, noAutoBrowser)
},
}
diff --git a/fs/config/authorize.go b/fs/config/authorize.go
index 4f44df4ee..0ef0b926a 100644
--- a/fs/config/authorize.go
+++ b/fs/config/authorize.go
@@ -2,8 +2,8 @@ package config
import (
"context"
- "log"
+ "github.com/pkg/errors"
"github.com/rclone/rclone/fs"
)
@@ -13,17 +13,17 @@ import (
//
// rclone authorize "fs name"
// rclone authorize "fs name" "client id" "client secret"
-func Authorize(ctx context.Context, args []string, noAutoBrowser bool) {
+func Authorize(ctx context.Context, args []string, noAutoBrowser bool) error {
ctx = suppressConfirm(ctx)
switch len(args) {
case 1, 3:
default:
- log.Fatalf("Invalid number of arguments: %d", len(args))
+ return errors.Errorf("invalid number of arguments: %d", len(args))
}
newType := args[0]
f := fs.MustFind(newType)
if f.Config == nil {
- log.Fatalf("Can't authorize fs %q", newType)
+ return errors.Errorf("can't authorize fs %q", newType)
}
// Name used for temporary fs
name := "**temp-fs**"
@@ -44,4 +44,5 @@ func Authorize(ctx context.Context, args []string, noAutoBrowser bool) {
m := fs.ConfigMap(f, name)
f.Config(ctx, name, m)
+ return nil
}
diff --git a/fs/config/crypt.go b/fs/config/crypt.go
index 98015f6c8..b6f03fa2c 100644
--- a/fs/config/crypt.go
+++ b/fs/config/crypt.go
@@ -10,7 +10,6 @@ import (
"fmt"
"io"
"io/ioutil"
- "log"
"os"
"os/exec"
"strings"
@@ -145,13 +144,13 @@ func Decrypt(b io.ReadSeeker) (io.Reader, error) {
if err != nil {
errRemove := os.Remove(envKeyFile)
if errRemove != nil {
- log.Fatalf("unable to read obscured config key and unable to delete the temp file: %v", err)
+ return nil, errors.Wrap(err, "unable to read obscured config key and unable to delete the temp file")
}
- log.Fatalf("unable to read obscured config key: %v", err)
+ return nil, errors.Wrap(err, "unable to read obscured config key")
}
errRemove := os.Remove(envKeyFile)
if errRemove != nil {
- log.Fatalf("unable to delete temp file with configKey: %v", err)
+ return nil, errors.Wrap(errRemove, "unable to delete temp file with configKey")
}
configKey = []byte(obscure.MustReveal(string(obscuredKey)))
fs.Debugf(nil, "using _RCLONE_CONFIG_KEY_FILE for configKey")
@@ -259,32 +258,32 @@ func SetConfigPassword(password string) error {
if PassConfigKeyForDaemonization {
tempFile, err := ioutil.TempFile("", "rclone")
if err != nil {
- log.Fatalf("cannot create temp file to store configKey: %v", err)
+ return errors.Wrap(err, "cannot create temp file to store configKey")
}
_, err = tempFile.WriteString(obscure.MustObscure(string(configKey)))
if err != nil {
errRemove := os.Remove(tempFile.Name())
if errRemove != nil {
- log.Fatalf("error writing configKey to temp file and also error deleting it: %v", err)
+ return errors.Wrap(err, "error writing configKey to temp file and also error deleting it")
}
- log.Fatalf("error writing configKey to temp file: %v", err)
+ return errors.Wrap(err, "error writing configKey to temp file")
}
err = tempFile.Close()
if err != nil {
errRemove := os.Remove(tempFile.Name())
if errRemove != nil {
- log.Fatalf("error closing temp file with configKey and also error deleting it: %v", err)
+ return errors.Wrap(err, "error closing temp file with configKey and also error deleting it")
}
- log.Fatalf("error closing temp file with configKey: %v", err)
+ return errors.Wrap(err, "error closing temp file with configKey")
}
fs.Debugf(nil, "saving configKey to temp file")
err = os.Setenv("_RCLONE_CONFIG_KEY_FILE", tempFile.Name())
if err != nil {
errRemove := os.Remove(tempFile.Name())
if errRemove != nil {
- log.Fatalf("unable to set environment variable _RCLONE_CONFIG_KEY_FILE and unable to delete the temp file: %v", err)
+ return errors.Wrap(err, "unable to set environment variable _RCLONE_CONFIG_KEY_FILE and unable to delete the temp file")
}
- log.Fatalf("unable to set environment variable _RCLONE_CONFIG_KEY_FILE: %v", err)
+ return errors.Wrap(err, "unable to set environment variable _RCLONE_CONFIG_KEY_FILE")
}
}
return nil