Improve error messages
This commit is contained in:
+1
-1
@@ -71,7 +71,7 @@ func mainAccess(ctx *cli.Context) {
|
||||
}
|
||||
for _, arg := range ctx.Args().Tail() {
|
||||
targetURL, err := getCanonicalizedURL(arg, config.Aliases)
|
||||
fatalIf(err, "Unable to parse URL argument ‘"+arg+"’.")
|
||||
fatalIf(err.Trace(), "Unable to parse URL argument ‘"+arg+"’.")
|
||||
|
||||
fatalIf(doUpdateAccessCmd(targetURL, acl).Trace(), "Unable to set access permission ‘"+acl.String()+"’ for URL ‘"+targetURL+"’.")
|
||||
}
|
||||
|
||||
+2
-2
@@ -70,11 +70,11 @@ func mainCat(ctx *cli.Context) {
|
||||
}
|
||||
|
||||
if stdinMode {
|
||||
fatalIf(catOut(os.Stdin), "Unable to read from stdin")
|
||||
fatalIf(catOut(os.Stdin).Trace(), "Unable to read from stdin")
|
||||
} else {
|
||||
// Convert arguments to URLs: expand alias, fix format...
|
||||
for _, arg := range ctx.Args() {
|
||||
fatalIf(catURL(arg), "Unable to read from URL")
|
||||
fatalIf(catURL(arg).Trace(), "Unable to read from URL")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+22
-26
@@ -17,6 +17,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/minio/mc/internal/github.com/minio/cli"
|
||||
@@ -64,63 +66,57 @@ func mainConfig(ctx *cli.Context) {
|
||||
arg := ctx.Args().First()
|
||||
tailArgs := ctx.Args().Tail()
|
||||
if len(tailArgs) > 2 {
|
||||
console.Fatalf("Incorrect number of arguments, please read \"mc config help\". %s", errInvalidArgument{})
|
||||
fatalIf(probe.NewError(errors.New("")),
|
||||
"Incorrect number of arguments, please read ‘mc config help’")
|
||||
}
|
||||
configPath, err := getMcConfigPath()
|
||||
fatalIf(err, "Unable to get mc config path")
|
||||
|
||||
switch arg {
|
||||
case "alias":
|
||||
config, err := addAlias(tailArgs)
|
||||
fatalIf(err, "Unable to set alias name")
|
||||
|
||||
err = writeConfig(config)
|
||||
fatalIf(err, "Unable to write alias name")
|
||||
if len(tailArgs) < 2 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "config", 1) // last argument is exit code
|
||||
}
|
||||
addAlias(tailArgs)
|
||||
default:
|
||||
fatalIf(probe.NewError(errInvalidArgument{}), "Unable to configure")
|
||||
cli.ShowCommandHelpAndExit(ctx, "config", 1) // last argument is exit code
|
||||
}
|
||||
// upon success
|
||||
console.Infoln("Alias written successfully to [" + configPath + "].")
|
||||
}
|
||||
|
||||
// addAlias - add new aliases
|
||||
func addAlias(aliases []string) (quick.Config, *probe.Error) {
|
||||
if len(aliases) < 2 {
|
||||
return nil, probe.NewError(errInvalidArgument{})
|
||||
}
|
||||
func addAlias(aliases []string) {
|
||||
conf := newConfigV1()
|
||||
config, err := quick.New(conf)
|
||||
if err != nil {
|
||||
return nil, err.Trace()
|
||||
}
|
||||
fatalIf(err.Trace(), "Unable to initialize quick config")
|
||||
|
||||
err = config.Load(mustGetMcConfigPath())
|
||||
if err != nil {
|
||||
return nil, err.Trace()
|
||||
}
|
||||
fatalIf(err.Trace(), "Unable to load config path")
|
||||
|
||||
aliasName := aliases[0]
|
||||
url := strings.TrimSuffix(aliases[1], "/")
|
||||
if strings.HasPrefix(aliasName, "http") {
|
||||
return nil, probe.NewError(errInvalidAliasName{alias: aliasName})
|
||||
fatalIf(probe.NewError(errors.New("")), fmt.Sprintf("Alias name ‘%s’ is invalid, valid examples are: Area51, Grand-Nagus..", aliasName))
|
||||
}
|
||||
if !strings.HasPrefix(url, "http") {
|
||||
return nil, probe.NewError(errInvalidURL{URL: url})
|
||||
fatalIf(probe.NewError(errors.New("")), fmt.Sprintf("Alias URL ‘%s’ is invalid, valid examples are: http://s3.amazonaws.com, https://yourbucket.example.com...", url))
|
||||
}
|
||||
if isAliasReserved(aliasName) {
|
||||
return nil, probe.NewError(errReservedAliasName{alias: aliasName})
|
||||
fatalIf(probe.NewError(errors.New("")), fmt.Sprintf("Alias name ‘%s’ is a reserved word, reserved words are [help, private, readonly, public, authenticated]", aliasName))
|
||||
}
|
||||
if !isValidAliasName(aliasName) {
|
||||
return nil, probe.NewError(errInvalidAliasName{alias: aliasName})
|
||||
fatalIf(probe.NewError(errors.New("")), fmt.Sprintf("Alias name ‘%s’ is invalid, valid examples are: Area51, Grand-Nagus..", aliasName))
|
||||
}
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV1)
|
||||
if _, ok := newConf.Aliases[aliasName]; ok {
|
||||
return nil, probe.NewError(errAliasExists{alias: aliasName})
|
||||
fatalIf(probe.NewError(errors.New("")), fmt.Sprintf("Specified alias name: ‘%s’ already exists.", aliasName))
|
||||
}
|
||||
newConf.Aliases[aliasName] = url
|
||||
newConfig, err := quick.New(newConf)
|
||||
if err != nil {
|
||||
return nil, err.Trace()
|
||||
}
|
||||
return newConfig, nil
|
||||
fatalIf(err.Trace(), "Unable to initialize quick config")
|
||||
|
||||
err = writeConfig(newConfig)
|
||||
fatalIf(err.Trace(), "Unable to write alias name")
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ func mustGetMcConfigPath() string {
|
||||
// getMcConfig - reads configuration file and returns config
|
||||
func getMcConfig() (*configV1, *probe.Error) {
|
||||
if !isMcConfigExists() {
|
||||
return nil, probe.NewError(errInvalidArgument{})
|
||||
return nil, probe.NewError(errInvalidArgument)
|
||||
}
|
||||
|
||||
configFile, err := getMcConfigPath()
|
||||
@@ -154,7 +154,7 @@ func isMcConfigExists() bool {
|
||||
// writeConfig - write configuration file
|
||||
func writeConfig(config quick.Config) *probe.Error {
|
||||
if config == nil {
|
||||
return probe.NewError(errInvalidArgument{})
|
||||
return probe.NewError(errInvalidArgument)
|
||||
}
|
||||
err := createMcConfigDir()
|
||||
if err != nil {
|
||||
@@ -181,10 +181,10 @@ func migrateConfigV1ToV101() {
|
||||
}
|
||||
conf := newConfigV1()
|
||||
config, err := quick.New(conf)
|
||||
fatalIf(err, "Unable to initialize quick config")
|
||||
fatalIf(err.Trace(), "Unable to initialize quick config")
|
||||
|
||||
err = config.Load(mustGetMcConfigPath())
|
||||
fatalIf(err, "Unable to load config")
|
||||
fatalIf(err.Trace(), "Unable to load config")
|
||||
|
||||
conf = config.Data().(*configV1)
|
||||
// version is the same return
|
||||
@@ -211,11 +211,11 @@ func migrateConfigV1ToV101() {
|
||||
conf.Hosts["*.s3*.amazonaws.com"] = s3HostConf
|
||||
}
|
||||
|
||||
newConfig, perr := quick.New(conf)
|
||||
fatalIf(perr, "Unable to initialize quick config")
|
||||
newConfig, err := quick.New(conf)
|
||||
fatalIf(err.Trace(), "Unable to initialize quick config")
|
||||
|
||||
perr = newConfig.Save(mustGetMcConfigPath())
|
||||
fatalIf(perr, "Unable to save config")
|
||||
err = newConfig.Save(mustGetMcConfigPath())
|
||||
fatalIf(err.Trace(), "Unable to save config")
|
||||
|
||||
console.Infof("Successfully migrated %s from version: %s to version: %s\n", mustGetMcConfigPath(), globalMCPreviousConfigVersion, globalMCCurrentConfigVersion)
|
||||
}
|
||||
|
||||
+2
-9
@@ -24,21 +24,14 @@ import (
|
||||
)
|
||||
|
||||
func (s *CmdTestSuite) TestConfigContext(c *C) {
|
||||
err := app.Run([]string{os.Args[0], "config", "invalid"})
|
||||
err := app.Run([]string{os.Args[0], "config", "alias", "test", "htt://test.io"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, true)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
err = app.Run([]string{os.Args[0], "config", "alias", "test", "htt://test.io"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, true)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
err = app.Run([]string{os.Args[0], "config", "alias", "test", "http://test.io"})
|
||||
err = app.Run([]string{os.Args[0], "config", "alias", "new", "http://test.io"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, false)
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func checkCopySyntax(ctx *cli.Context) {
|
||||
/****** Generic rules *******/
|
||||
// Recursive URLs are not allowed in target.
|
||||
if isURLRecursive(tgtURL) {
|
||||
console.Fatalf("Recursive option is not supported for target ‘%s’ argument. %s\n", tgtURL, probe.NewError(errInvalidArgument{}))
|
||||
console.Fatalf("Recursive option is not supported for target ‘%s’ argument. %s\n", tgtURL, probe.NewError(errInvalidArgument))
|
||||
}
|
||||
// scope locally
|
||||
{
|
||||
@@ -104,14 +104,14 @@ func checkCopySyntax(ctx *cli.Context) {
|
||||
// checkCopySyntaxTypeA verifies if the source and target are valid file arguments.
|
||||
func checkCopySyntaxTypeA(srcURLs []string, tgtURL string) {
|
||||
if len(srcURLs) != 1 {
|
||||
console.Fatalf("Invalid number of source arguments to copy command. %s\n", probe.NewError(errInvalidArgument{}))
|
||||
console.Fatalf("Invalid number of source arguments to copy command. %s\n", probe.NewError(errInvalidArgument))
|
||||
}
|
||||
srcURL := srcURLs[0]
|
||||
_, srcContent, err := url2Stat(srcURL)
|
||||
fatalIf(err, "Unable to stat source URL")
|
||||
fatalIf(err.Trace(), "Unable to stat source URL")
|
||||
|
||||
if srcContent.Type.IsDir() {
|
||||
console.Fatalf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively. %s\n", srcURL, srcURL, errInvalidArgument{})
|
||||
console.Fatalf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively. %s\n", srcURL, srcURL, errInvalidArgument)
|
||||
}
|
||||
if !srcContent.Type.IsRegular() {
|
||||
fatalIf(probe.NewError(errSourceIsNotFile{URL: srcURL}), "Invalid source type")
|
||||
@@ -121,14 +121,14 @@ func checkCopySyntaxTypeA(srcURLs []string, tgtURL string) {
|
||||
// checkCopySyntaxTypeB verifies if the source is a valid file and target is a valid dir.
|
||||
func checkCopySyntaxTypeB(srcURLs []string, tgtURL string) {
|
||||
if len(srcURLs) != 1 {
|
||||
console.Fatalf("Invalid number of source arguments to copy command. %s\n", errInvalidArgument{})
|
||||
console.Fatalf("Invalid number of source arguments to copy command. %s\n", errInvalidArgument)
|
||||
}
|
||||
srcURL := srcURLs[0]
|
||||
_, srcContent, err := url2Stat(srcURL)
|
||||
fatalIf(err, "Unable to stat source URL")
|
||||
fatalIf(err.Trace(), "Unable to stat source URL")
|
||||
|
||||
if srcContent.Type.IsDir() {
|
||||
console.Fatalf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively. %s\n", srcURL, srcURL, errInvalidArgument{})
|
||||
console.Fatalf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively. %s\n", srcURL, srcURL, errInvalidArgument)
|
||||
}
|
||||
if !srcContent.Type.IsRegular() {
|
||||
fatalIf(probe.NewError(errSourceIsNotFile{URL: srcURL}), "Invalid source type")
|
||||
@@ -146,12 +146,12 @@ func checkCopySyntaxTypeB(srcURLs []string, tgtURL string) {
|
||||
// checkCopySyntaxTypeC verifies if the source is a valid recursive dir and target is a valid dir.
|
||||
func checkCopySyntaxTypeC(srcURLs []string, tgtURL string) {
|
||||
if len(srcURLs) != 1 {
|
||||
console.Fatalf("Invalid number of source arguments to copy command. %s\n", errInvalidArgument{})
|
||||
console.Fatalf("Invalid number of source arguments to copy command. %s\n", errInvalidArgument)
|
||||
}
|
||||
srcURL := srcURLs[0]
|
||||
srcURL = stripRecursiveURL(srcURL)
|
||||
_, srcContent, err := url2Stat(srcURL)
|
||||
fatalIf(err, "Unable to stat source URL")
|
||||
fatalIf(err.Trace(), "Unable to stat source URL")
|
||||
|
||||
if srcContent.Type.IsRegular() { // Ellipses is supported only for folders.
|
||||
fatalIf(probe.NewError(errSourceIsNotDir{URL: srcURL}), "Invalid source type")
|
||||
@@ -171,17 +171,17 @@ func checkCopySyntaxTypeD(srcURLs []string, tgtURL string) {
|
||||
if isURLRecursive(srcURL) {
|
||||
srcURL = stripRecursiveURL(srcURL)
|
||||
_, srcContent, err := url2Stat(srcURL)
|
||||
fatalIf(err, "Unable to stat source URL")
|
||||
fatalIf(err.Trace(), "Unable to stat source URL")
|
||||
|
||||
if !srcContent.Type.IsDir() { // Ellipses is supported only for folders.
|
||||
fatalIf(probe.NewError(errSourceIsNotDir{URL: srcURL}), "Invalid source type")
|
||||
}
|
||||
} else { // Regular URL.
|
||||
_, srcContent, err := url2Stat(srcURL)
|
||||
fatalIf(err, "Unable to stat source URL")
|
||||
fatalIf(err.Trace(), "Unable to stat source URL")
|
||||
|
||||
if srcContent.Type.IsDir() {
|
||||
console.Fatalf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively. %s\n", srcURL, srcURL, errInvalidArgument{})
|
||||
console.Fatalf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively. %s\n", srcURL, srcURL, errInvalidArgument)
|
||||
}
|
||||
if !srcContent.Type.IsRegular() {
|
||||
fatalIf(probe.NewError(errSourceIsNotFile{URL: srcURL}), "Unable to read from source url")
|
||||
@@ -353,7 +353,7 @@ func prepareCopyURLsTypeD(sourceURLs []string, targetURL string) <-chan copyURLs
|
||||
|
||||
if sourceURLs == nil {
|
||||
// Source list is empty.
|
||||
copyURLsCh <- copyURLs{Error: probe.NewError(errSourceListEmpty{})}
|
||||
copyURLsCh <- copyURLs{Error: probe.NewError(errSourceListEmpty)}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -391,7 +391,7 @@ func prepareCopyURLs(sourceURLs []string, targetURL string) <-chan copyURLs {
|
||||
copyURLsCh <- cURLs
|
||||
}
|
||||
default:
|
||||
copyURLsCh <- copyURLs{Error: probe.NewError(errInvalidArgument{})}
|
||||
copyURLsCh <- copyURLs{Error: probe.NewError(errInvalidArgument)}
|
||||
}
|
||||
}(sourceURLs, targetURL, copyURLsCh)
|
||||
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ func mainDiff(ctx *cli.Context) {
|
||||
fatalIf(err, "Unable to canonicalize second URL.")
|
||||
|
||||
if isURLRecursive(secondURL) {
|
||||
console.Fatalf("Second URL cannot be recursive. %s\n", errInvalidArgument{})
|
||||
console.Fatalf("Second URL cannot be recursive. %s\n", errInvalidArgument)
|
||||
}
|
||||
newFirstURL := stripRecursiveURL(firstURL)
|
||||
for diff := range doDiffCmd(newFirstURL, secondURL, isURLRecursive(firstURL)) {
|
||||
|
||||
+2
-2
@@ -60,9 +60,9 @@ func mainMakeBucket(ctx *cli.Context) {
|
||||
config := mustGetMcConfig()
|
||||
for _, arg := range ctx.Args() {
|
||||
targetURL, err := getCanonicalizedURL(arg, config.Aliases)
|
||||
fatalIf(err, "Unable to canonicalize URL")
|
||||
fatalIf(err.Trace(), "Unable to canonicalize URL")
|
||||
|
||||
fatalIf(doMakeBucketCmd(targetURL), "Unable to make bucket")
|
||||
fatalIf(doMakeBucketCmd(targetURL).Trace(), "Unable to make bucket")
|
||||
|
||||
console.Infoln("Bucket created successfully : " + targetURL)
|
||||
}
|
||||
|
||||
+4
-4
@@ -57,7 +57,7 @@ func checkMirrorSyntax(ctx *cli.Context) {
|
||||
|
||||
// extract URLs.
|
||||
URLs, err := args2URLs(ctx.Args())
|
||||
fatalIf(err, "Unable to convert args to URLs")
|
||||
fatalIf(err.Trace(), "Unable to convert args to URLs")
|
||||
|
||||
srcURL := URLs[0]
|
||||
tgtURLs := URLs[1:]
|
||||
@@ -66,7 +66,7 @@ func checkMirrorSyntax(ctx *cli.Context) {
|
||||
// Source cannot be a folder (except when recursive)
|
||||
if !isURLRecursive(srcURL) {
|
||||
_, srcContent, err := url2Stat(srcURL)
|
||||
fatalIf(err, "Unable to stat URL")
|
||||
fatalIf(err.Trace(), "Unable to stat URL")
|
||||
|
||||
if !srcContent.Type.IsRegular() {
|
||||
if srcContent.Type.IsDir() {
|
||||
@@ -89,11 +89,11 @@ func checkMirrorSyntax(ctx *cli.Context) {
|
||||
}
|
||||
|
||||
if len(tgtURLs) == 0 && tgtURLs == nil {
|
||||
console.Fatalf("Invalid number of target arguments to mirror command. %s\n", errInvalidArgument{})
|
||||
console.Fatalf("Invalid number of target arguments to mirror command. %s\n", errInvalidArgument)
|
||||
}
|
||||
|
||||
_, srcContent, err := url2Stat(stripRecursiveURL(srcURL))
|
||||
fatalIf(err, "Unable to stat source URL.")
|
||||
fatalIf(err.Trace(), "Unable to stat source URL.")
|
||||
|
||||
if srcContent.Type.IsRegular() { // Ellipses is supported only for folders.
|
||||
fatalIf(probe.NewError(errSourceIsNotDir{URL: srcURL}), "Invalid source type.")
|
||||
|
||||
@@ -25,8 +25,10 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/minio/mc/internal/github.com/dustin/go-humanize"
|
||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
||||
"github.com/minio/mc/internal/github.com/minio/pb"
|
||||
"github.com/minio/mc/internal/github.com/olekukonko/ts"
|
||||
|
||||
"github.com/minio/mc/pkg/console"
|
||||
)
|
||||
|
||||
@@ -224,7 +226,7 @@ func scanBarFactory(prefix string) scanBarFunc {
|
||||
fileCount := 0
|
||||
termSize, err := ts.GetSize()
|
||||
if err != nil {
|
||||
console.Fatalf("Unable to get terminal size. %s\n", err)
|
||||
fatalIf(probe.NewError(err), "Unable to get terminal size.")
|
||||
}
|
||||
termWidth := termSize.Col()
|
||||
cursorCh := cursorAnimate()
|
||||
|
||||
+30
-30
@@ -85,9 +85,9 @@ func clearSession(sid string) {
|
||||
if sid == "all" {
|
||||
for _, sid := range getSessionIDs() {
|
||||
session, err := loadSessionV2(sid)
|
||||
fatalIf(err, "Unable to load session")
|
||||
fatalIf(err.Trace(), "Unable to load session ‘"+sid+"’")
|
||||
|
||||
session.Delete()
|
||||
fatalIf(session.Delete().Trace(), "Unable to load session ‘"+sid+"’")
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -97,10 +97,10 @@ func clearSession(sid string) {
|
||||
}
|
||||
|
||||
session, err := loadSessionV2(sid)
|
||||
fatalIf(err, "Unable to load session")
|
||||
fatalIf(err.Trace(), "Unable to load session ‘"+sid+"’")
|
||||
|
||||
if session != nil {
|
||||
session.Delete()
|
||||
fatalIf(session.Delete().Trace(), "Unable to load session ‘"+sid+"’")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ func mainSession(ctx *cli.Context) {
|
||||
cli.ShowCommandHelpAndExit(ctx, "session", 1) // last argument is exit code
|
||||
}
|
||||
if !isSessionDirExists() {
|
||||
fatalIf(createSessionDir(), "Unable to create session")
|
||||
fatalIf(createSessionDir(), "Unable to create session directory")
|
||||
}
|
||||
switch strings.TrimSpace(ctx.Args().First()) {
|
||||
// list resumable sessions
|
||||
@@ -137,41 +137,41 @@ func mainSession(ctx *cli.Context) {
|
||||
|
||||
sid := strings.TrimSpace(ctx.Args().Tail().First())
|
||||
|
||||
if _, err := os.Stat(getSessionFile(sid)); err != nil {
|
||||
console.Fatalln(errInvalidSessionID{id: sid})
|
||||
if !isSession(sid) {
|
||||
console.Fatalf("Session ‘%s’ not found.\n", sid)
|
||||
}
|
||||
s, err := loadSessionV2(sid)
|
||||
fatalIf(err, "Unable to load session")
|
||||
|
||||
s, perr := loadSessionV2(sid)
|
||||
fatalIf(perr.Trace(), "Unable to load session")
|
||||
|
||||
// extra check for testing purposes
|
||||
if s == nil {
|
||||
return
|
||||
}
|
||||
{
|
||||
savedCwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
console.Fatalln("Unable to verify your current working folder. %s\n", err)
|
||||
}
|
||||
if s.Header.RootPath != "" {
|
||||
// chdir to RootPath
|
||||
os.Chdir(s.Header.RootPath)
|
||||
}
|
||||
|
||||
sessionExecute(s)
|
||||
{
|
||||
err := s.Close()
|
||||
if err != nil {
|
||||
console.Fatalf("Unable to close session file properly. %s\n", err)
|
||||
}
|
||||
err = s.Delete()
|
||||
if err != nil {
|
||||
console.Fatalf("Unable to clear session files properly. %s\n", err)
|
||||
}
|
||||
savedCwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
console.Fatalf("Unable to verify your current working folder. %s\n", err)
|
||||
}
|
||||
if s.Header.RootPath != "" {
|
||||
// chdir to RootPath
|
||||
if err := os.Chdir(s.Header.RootPath); err != nil {
|
||||
console.Fatalf("Unable to change directory to root path while resuming session. %s\n", err)
|
||||
}
|
||||
// change dir back
|
||||
os.Chdir(savedCwd)
|
||||
}
|
||||
|
||||
sessionExecute(s)
|
||||
perr = s.Close()
|
||||
fatalIf(perr.Trace(), "Unable to close session file properly.")
|
||||
|
||||
perr = s.Delete()
|
||||
fatalIf(perr.Trace(), "Unable to clear session files properly.")
|
||||
|
||||
// change dir back
|
||||
err = os.Chdir(savedCwd)
|
||||
if err != nil {
|
||||
console.Fatalf("Unable to change directory to saved path. %s\n", err)
|
||||
}
|
||||
// purge a requested pending session, if "*" purge everything
|
||||
case "clear":
|
||||
if len(ctx.Args().Tail()) != 1 {
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ func (s sessionV1) String() string {
|
||||
// loadSession - reads session file if exists and re-initiates internal variables
|
||||
func loadSessionV1(sid string) (*sessionV1, *probe.Error) {
|
||||
if !isSessionDirExists() {
|
||||
return nil, probe.NewError(errInvalidArgument{})
|
||||
return nil, probe.NewError(errInvalidArgument)
|
||||
}
|
||||
sessionFile := getSessionFileV1(sid)
|
||||
|
||||
|
||||
+5
-4
@@ -19,6 +19,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"sync"
|
||||
@@ -167,7 +168,7 @@ func (s *sessionV2) Delete() *probe.Error {
|
||||
// loadSession - reads session file if exists and re-initiates internal variables
|
||||
func loadSessionV2(sid string) (*sessionV2, *probe.Error) {
|
||||
if !isSessionDirExists() {
|
||||
return nil, probe.NewError(errInvalidArgument{})
|
||||
return nil, probe.NewError(errInvalidArgument)
|
||||
}
|
||||
sessionFile := getSessionFile(sid)
|
||||
if _, err := os.Stat(sessionFile); err != nil {
|
||||
@@ -193,8 +194,7 @@ func loadSessionV2(sid string) (*sessionV2, *probe.Error) {
|
||||
var err error
|
||||
s.DataFP, err = os.Open(getSessionDataFile(s.SessionID))
|
||||
if err != nil {
|
||||
// fail proactively here
|
||||
console.Fatalf("Unable to open session data file \""+getSessionDataFile(s.SessionID)+"\". %s\n", err)
|
||||
return nil, probe.NewError(err)
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
@@ -206,7 +206,8 @@ func isCopiedFactory(lastCopied string) func(string) bool {
|
||||
copied := true // closure
|
||||
return func(sourceURL string) bool {
|
||||
if sourceURL == "" {
|
||||
console.Fatalf("Empty source URL passed to isCopied() function. %s\n", probe.NewError(errUnexpected{}))
|
||||
fatalIf(probe.NewError(errors.New("")),
|
||||
"Empty source URL passed to isCopied() function. please report this bug at https://github.com/minio/mc/issues.")
|
||||
}
|
||||
if lastCopied == "" {
|
||||
return false
|
||||
|
||||
+3
-58
@@ -16,29 +16,7 @@
|
||||
|
||||
package main
|
||||
|
||||
type errUnexpected struct{}
|
||||
|
||||
func (e errUnexpected) Error() string {
|
||||
return "Unexpected control flow, please report this bug at https://github.com/minio/mc/issues."
|
||||
}
|
||||
|
||||
type errInvalidSessionID struct {
|
||||
id string
|
||||
}
|
||||
|
||||
func (e errInvalidSessionID) Error() string {
|
||||
return "Invalid session id ‘" + e.id + "’."
|
||||
}
|
||||
|
||||
/*
|
||||
type errInvalidACL struct {
|
||||
acl string
|
||||
}
|
||||
|
||||
func (e errInvalidACL) Error() string {
|
||||
return "Invalid ACL Type ‘" + e.acl + "’. Valid types are [private, public, readonly]."
|
||||
}
|
||||
*/
|
||||
import "errors"
|
||||
|
||||
type errNotAnObject struct {
|
||||
url string
|
||||
@@ -48,11 +26,7 @@ func (e errNotAnObject) Error() string {
|
||||
return "URL: ‘" + e.url + "’ not an object"
|
||||
}
|
||||
|
||||
type errInvalidArgument struct{}
|
||||
|
||||
func (e errInvalidArgument) Error() string {
|
||||
return "Incorrect usage, please use \"mc config help\""
|
||||
}
|
||||
var errInvalidArgument = errors.New("Invalid arguments provided, cannot proceed")
|
||||
|
||||
type errInvalidGlobURL struct {
|
||||
glob string
|
||||
@@ -63,22 +37,6 @@ func (e errInvalidGlobURL) Error() string {
|
||||
return "Error reading glob URL " + e.glob + " while comparing with " + e.request
|
||||
}
|
||||
|
||||
type errReservedAliasName struct {
|
||||
alias string
|
||||
}
|
||||
|
||||
func (e errReservedAliasName) Error() string {
|
||||
return "Alias name ‘" + e.alias + "’ is a reserved word, reserved words are [help, private, readonly, public, authenticated]"
|
||||
}
|
||||
|
||||
type errInvalidAliasName struct {
|
||||
alias string
|
||||
}
|
||||
|
||||
func (e errInvalidAliasName) Error() string {
|
||||
return "Alias name ‘" + e.alias + "’ is invalid, valid examples are: Area51, Grand-Nagus.."
|
||||
}
|
||||
|
||||
type errNoMatchingHost struct {
|
||||
url string
|
||||
}
|
||||
@@ -87,15 +45,6 @@ func (e errNoMatchingHost) Error() string {
|
||||
return "No matching host found for the given url ‘" + e.url + "’"
|
||||
}
|
||||
|
||||
// errAliasExists - alias exists
|
||||
type errAliasExists struct {
|
||||
alias string
|
||||
}
|
||||
|
||||
func (e errAliasExists) Error() string {
|
||||
return "Alias name: ‘" + e.alias + "’ already exists."
|
||||
}
|
||||
|
||||
type errInitClient struct {
|
||||
url string
|
||||
}
|
||||
@@ -148,8 +97,4 @@ func (e errSourceIsNotFile) Error() string {
|
||||
return "Source ‘" + e.URL + "’ is not a file."
|
||||
}
|
||||
|
||||
type errSourceListEmpty errInvalidArgument
|
||||
|
||||
func (e errSourceListEmpty) Error() string {
|
||||
return "Source list is empty."
|
||||
}
|
||||
var errSourceListEmpty = errors.New("Source list is empty.")
|
||||
|
||||
+2
-2
@@ -61,10 +61,10 @@ func mainUpdate(ctx *cli.Context) {
|
||||
cli.ShowCommandHelpAndExit(ctx, "update", 1) // last argument is exit code
|
||||
}
|
||||
clnt, err := url2Client(mcUpdateURL)
|
||||
fatalIf(err, "Unable to initalize update URL")
|
||||
fatalIf(err.Trace(), "Unable to initalize update URL")
|
||||
|
||||
data, _, err := clnt.GetObject(0, 0)
|
||||
fatalIf(err, "Unable to read update URL")
|
||||
fatalIf(err.Trace(), "Unable to read update URL")
|
||||
|
||||
current, goerr := time.Parse(time.RFC3339Nano, Version)
|
||||
fatalIf(probe.NewError(goerr), "Unable to parse Version as time")
|
||||
|
||||
+5
-5
@@ -107,14 +107,14 @@ func checkGolangRuntimeVersion() {
|
||||
|
||||
func verifyMCRuntime() {
|
||||
if !isMcConfigExists() {
|
||||
if err := createMcConfigDir(); err != nil {
|
||||
console.Fatalf("Unable to create ‘mc’ config folder. %s\n", err)
|
||||
}
|
||||
err := createMcConfigDir()
|
||||
fatalIf(err.Trace(), "Unable to create ‘mc’ config folder.")
|
||||
|
||||
config, err := newConfig()
|
||||
fatalIf(err, "Unable to initialize newConfig")
|
||||
fatalIf(err.Trace(), "Unable to initialize newConfig")
|
||||
|
||||
err = writeConfig(config)
|
||||
fatalIf(err, "Unable to write newConfig")
|
||||
fatalIf(err.Trace(), "Unable to write newConfig")
|
||||
|
||||
console.Infoln("Configuration written to [" + mustGetMcConfigPath() + "]. Please update your access credentials.")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user