diff --git a/access-main.go b/access-main.go index 46b74e89..15ef72ce 100644 --- a/access-main.go +++ b/access-main.go @@ -64,7 +64,7 @@ func mainAccess(ctx *cli.Context) { config := mustGetMcConfig() acl := bucketACL(ctx.Args().First()) if !acl.isValidBucketACL() { - fatalIf(errDummy.Trace(), + fatalIf(errDummy().Trace(), "Unrecognized permission ‘"+acl.String()+"’. Allowed values are [private, public, readonly].") } for _, arg := range ctx.Args().Tail() { diff --git a/config-main.go b/config-main.go index 994a65dd..172a41ce 100644 --- a/config-main.go +++ b/config-main.go @@ -95,7 +95,7 @@ func mainConfig(ctx *cli.Context) { arg := ctx.Args().First() tailArgs := ctx.Args().Tail() if len(tailArgs) > 2 { - fatalIf(errDummy.Trace(), "Incorrect number of arguments to config command. Please read ‘mc config help’") + fatalIf(errDummy().Trace(), "Incorrect number of arguments to config command. Please read ‘mc config help’") } switch arg { @@ -129,7 +129,7 @@ func mainConfig(ctx *cli.Context) { // addAlias - add new aliases func addAlias(alias, url string) { if alias == "" || url == "" { - fatalIf(errDummy.Trace(), "Alias or URL cannot be empty.") + fatalIf(errDummy().Trace(), "Alias or URL cannot be empty.") } conf := newConfigV2() config, err := quick.New(conf) @@ -140,18 +140,18 @@ func addAlias(alias, url string) { url = strings.TrimSuffix(url, "/") if !strings.HasPrefix(url, "http") { - fatalIf(errDummy.Trace(), fmt.Sprintf("Invalid alias URL ‘%s’. Valid examples are: http://s3.amazonaws.com, https://yourbucket.example.com.", url)) + fatalIf(errDummy().Trace(), fmt.Sprintf("Invalid alias URL ‘%s’. Valid examples are: http://s3.amazonaws.com, https://yourbucket.example.com.", url)) } if isAliasReserved(alias) { - fatalIf(errDummy.Trace(), fmt.Sprintf("Cannot use a reserved name ‘%s’ as an alias. Following are reserved names: [help, private, readonly, public, authenticated].", alias)) + fatalIf(errDummy().Trace(), fmt.Sprintf("Cannot use a reserved name ‘%s’ as an alias. Following are reserved names: [help, private, readonly, public, authenticated].", alias)) } if !isValidAliasName(alias) { - fatalIf(errDummy.Trace(), fmt.Sprintf("Alias name ‘%s’ is invalid, valid examples are: mybucket, Area51, Grand-Nagus", alias)) + fatalIf(errDummy().Trace(), fmt.Sprintf("Alias name ‘%s’ is invalid, valid examples are: mybucket, Area51, Grand-Nagus", alias)) } // convert interface{} back to its original struct newConf := config.Data().(*configV2) if oldURL, ok := newConf.Aliases[alias]; ok { - fatalIf(errDummy.Trace(), fmt.Sprintf("Alias ‘%s’ already exists for ‘%s’.", alias, oldURL)) + fatalIf(errDummy().Trace(), fmt.Sprintf("Alias ‘%s’ already exists for ‘%s’.", alias, oldURL)) } newConf.Aliases[alias] = url newConfig, err := quick.New(newConf) diff --git a/config.go b/config.go index 1ffeaf86..6af5bac7 100644 --- a/config.go +++ b/config.go @@ -107,7 +107,7 @@ func mustGetMcConfigPath() string { // getMcConfig - reads configuration file and returns config func getMcConfig() (*configV2, *probe.Error) { if !isMcConfigExists() { - return nil, errInvalidArgument.Trace() + return nil, errInvalidArgument().Trace() } configFile, err := getMcConfigPath() @@ -158,7 +158,7 @@ func isMcConfigExists() bool { // writeConfig - write configuration file func writeConfig(config quick.Config) *probe.Error { if config == nil { - return errInvalidArgument.Trace() + return errInvalidArgument().Trace() } err := createMcConfigDir() if err != nil { diff --git a/cp-url.go b/cp-url.go index 3dbd0be8..6b0bfe00 100644 --- a/cp-url.go +++ b/cp-url.go @@ -71,7 +71,7 @@ func checkCopySyntax(ctx *cli.Context) { /****** Generic rules *******/ // Recursive URLs are not allowed in target. if isURLRecursive(tgtURL) { - fatalIf(errDummy.Trace(), fmt.Sprintf("Recursive option is not supported for target ‘%s’ argument.", tgtURL)) + fatalIf(errDummy().Trace(), fmt.Sprintf("Recursive option is not supported for target ‘%s’ argument.", tgtURL)) } // scope locally { @@ -81,7 +81,7 @@ func checkCopySyntax(ctx *cli.Context) { } if url.Host != "" { if url.Path == string(url.Separator) { - fatalIf(errInvalidArgument.Trace(), fmt.Sprintf("Target ‘%s’ does not contain bucket name.", tgtURL)) + fatalIf(errInvalidArgument().Trace(), fmt.Sprintf("Target ‘%s’ does not contain bucket name.", tgtURL)) } } } @@ -95,14 +95,14 @@ func checkCopySyntax(ctx *cli.Context) { case copyURLsTypeD: // File | Folder... -> Folder. checkCopySyntaxTypeD(srcURLs, tgtURL) default: - fatalIf(errInvalidArgument.Trace(), "Invalid arguments to copy command.") + fatalIf(errInvalidArgument().Trace(), "Invalid arguments to copy command.") } } // checkCopySyntaxTypeA verifies if the source and target are valid file arguments. func checkCopySyntaxTypeA(srcURLs []string, tgtURL string) { if len(srcURLs) != 1 { - fatalIf(errInvalidArgument.Trace(), "Invalid number of source arguments to copy command.") + fatalIf(errInvalidArgument().Trace(), "Invalid number of source arguments to copy command.") } srcURL := srcURLs[0] _, srcContent, err := url2Stat(srcURL) @@ -110,34 +110,34 @@ func checkCopySyntaxTypeA(srcURLs []string, tgtURL string) { fatalIf(err.Trace(srcURL), "Unable to stat source ‘"+srcURL+"’.") if srcContent.Type.IsDir() { - fatalIf(errInvalidArgument.Trace(), fmt.Sprintf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively.", srcURL, srcURL)) + fatalIf(errInvalidArgument().Trace(), fmt.Sprintf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively.", srcURL, srcURL)) } if !srcContent.Type.IsRegular() { - fatalIf(errInvalidArgument.Trace(), "Source ‘"+srcURL+"’ is not a file.") + fatalIf(errInvalidArgument().Trace(), "Source ‘"+srcURL+"’ is not a file.") } } // 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 { - fatalIf(errInvalidArgument.Trace(), "Invalid number of source arguments to copy command.") + fatalIf(errInvalidArgument().Trace(), "Invalid number of source arguments to copy command.") } srcURL := srcURLs[0] _, srcContent, err := url2Stat(srcURL) fatalIf(err.Trace(srcURL), "Unable to stat source ‘"+srcURL+"’.") if srcContent.Type.IsDir() { - fatalIf(errInvalidArgument.Trace(), fmt.Sprintf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively.", srcURL, srcURL)) + fatalIf(errInvalidArgument().Trace(), fmt.Sprintf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively.", srcURL, srcURL)) } if !srcContent.Type.IsRegular() { - fatalIf(errInvalidArgument.Trace(), "Source ‘"+srcURL+"’ is not a file.") + fatalIf(errInvalidArgument().Trace(), "Source ‘"+srcURL+"’ is not a file.") } _, tgtContent, err := url2Stat(tgtURL) // Target exist?. if err == nil { if !tgtContent.Type.IsDir() { - fatalIf(errInvalidArgument.Trace(), "Target ‘"+tgtURL+"’ is not a folder.") + fatalIf(errInvalidArgument().Trace(), "Target ‘"+tgtURL+"’ is not a folder.") } } } @@ -145,7 +145,7 @@ 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 { - fatalIf(errInvalidArgument.Trace(), "Invalid number of source arguments to copy command.") + fatalIf(errInvalidArgument().Trace(), "Invalid number of source arguments to copy command.") } srcURL := srcURLs[0] srcURL = stripRecursiveURL(srcURL) @@ -153,13 +153,13 @@ func checkCopySyntaxTypeC(srcURLs []string, tgtURL string) { fatalIf(err.Trace(srcURL), "Unable to stat source ‘"+srcURL+"’.") if srcContent.Type.IsRegular() { // Ellipses is supported only for folders. - fatalIf(errInvalidArgument.Trace(), "Source ‘"+srcURL+"’ is not a folder.") + fatalIf(errInvalidArgument().Trace(), "Source ‘"+srcURL+"’ is not a folder.") } _, tgtContent, err := url2Stat(tgtURL) // Target exist?. if err == nil { if !tgtContent.Type.IsDir() { - fatalIf(errInvalidArgument.Trace(), "Target ‘"+tgtURL+"’ is not a folder.") + fatalIf(errInvalidArgument().Trace(), "Target ‘"+tgtURL+"’ is not a folder.") } } } @@ -173,17 +173,17 @@ func checkCopySyntaxTypeD(srcURLs []string, tgtURL string) { fatalIf(err.Trace(srcURL), "Unable to stat source ‘"+srcURL+"’.") if !srcContent.Type.IsDir() { // Ellipses is supported only for folders. - fatalIf(errInvalidArgument.Trace(), "Source ‘"+srcURL+"’ is not a folder.") + fatalIf(errInvalidArgument().Trace(), "Source ‘"+srcURL+"’ is not a folder.") } } else { // Regular URL. _, srcContent, err := url2Stat(srcURL) fatalIf(err.Trace(srcURL), "Unable to stat source ‘"+srcURL+"’.") if srcContent.Type.IsDir() { - fatalIf(errInvalidArgument.Trace(), fmt.Sprintf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively.", srcURL, srcURL)) + fatalIf(errInvalidArgument().Trace(), fmt.Sprintf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively.", srcURL, srcURL)) } if !srcContent.Type.IsRegular() { - fatalIf(errInvalidArgument.Trace(), "Source ‘"+srcURL+"’ is not a file.") + fatalIf(errInvalidArgument().Trace(), "Source ‘"+srcURL+"’ is not a file.") } } } @@ -191,7 +191,7 @@ func checkCopySyntaxTypeD(srcURLs []string, tgtURL string) { // Target exist?. if err == nil { if !tgtContent.Type.IsDir() { - fatalIf(errInvalidArgument.Trace(), "Target ‘"+tgtURL+"’ is not a folder.") + fatalIf(errInvalidArgument().Trace(), "Target ‘"+tgtURL+"’ is not a folder.") } } } @@ -352,7 +352,7 @@ func prepareCopyURLsTypeD(sourceURLs []string, targetURL string) <-chan copyURLs if sourceURLs == nil { // Source list is empty. - copyURLsCh <- copyURLs{Error: errSourceListEmpty.Trace()} + copyURLsCh <- copyURLs{Error: errSourceListEmpty().Trace()} return } @@ -390,7 +390,7 @@ func prepareCopyURLs(sourceURLs []string, targetURL string) <-chan copyURLs { copyURLsCh <- cURLs } default: - copyURLsCh <- copyURLs{Error: errInvalidArgument.Trace()} + copyURLsCh <- copyURLs{Error: errInvalidArgument().Trace()} } }(sourceURLs, targetURL, copyURLsCh) diff --git a/diff-main.go b/diff-main.go index 528e3098..e48146fe 100644 --- a/diff-main.go +++ b/diff-main.go @@ -77,7 +77,7 @@ func mainDiff(ctx *cli.Context) { fatalIf(err.Trace(secondArg), "Unable to parse second argument ‘"+secondArg+"’.") if isURLRecursive(secondURL) { - fatalIf(errInvalidArgument.Trace(), "Second argument ‘"+secondURL+"’ cannot be recursive.") + fatalIf(errInvalidArgument().Trace(), "Second argument ‘"+secondURL+"’ cannot be recursive.") } newFirstURL := stripRecursiveURL(firstURL) for diff := range doDiffCmd(newFirstURL, secondURL, isURLRecursive(firstURL)) { diff --git a/diff.go b/diff.go index d7a489a3..c449d61b 100644 --- a/diff.go +++ b/diff.go @@ -64,7 +64,7 @@ func (d DiffMessage) String() string { case "size": msg = console.Colorize("DiffMessage", "‘"+d.FirstURL+"’"+" and "+"‘"+d.SecondURL+"’") + console.Colorize("DiffSize", " - differ in size.") default: - fatalIf(errDummy.Trace(), "Unhandled difference between ‘"+d.FirstURL+"’ and ‘"+d.SecondURL+"’.") + fatalIf(errDummy().Trace(), "Unhandled difference between ‘"+d.FirstURL+"’ and ‘"+d.SecondURL+"’.") } return msg } diff --git a/main.go b/main.go index 388b4ddb..c4716720 100644 --- a/main.go +++ b/main.go @@ -149,7 +149,7 @@ VERSION: {{end}} ` app.CommandNotFound = func(ctx *cli.Context, command string) { - fatalIf(errDummy.Trace(), fmt.Sprintf("Command ‘%s’ not found.", command)) + fatalIf(errDummy().Trace(), fmt.Sprintf("Command ‘%s’ not found.", command)) } return app } diff --git a/mirror-url.go b/mirror-url.go index e6c9149e..5dba35a0 100644 --- a/mirror-url.go +++ b/mirror-url.go @@ -83,7 +83,7 @@ func checkMirrorSyntax(ctx *cli.Context) { /****** Generic rules *******/ // Source cannot be a folder (except when recursive) if !isURLRecursive(srcURL) { - fatalIf(errInvalidArgument.Trace(), fmt.Sprintf("Source ‘%s’ is not recursive. Use ‘%s...’ as argument to mirror recursively.", srcURL, srcURL)) + fatalIf(errInvalidArgument().Trace(), fmt.Sprintf("Source ‘%s’ is not recursive. Use ‘%s...’ as argument to mirror recursively.", srcURL, srcURL)) } // Recursive source URL. newSrcURL := stripRecursiveURL(srcURL) @@ -91,17 +91,17 @@ func checkMirrorSyntax(ctx *cli.Context) { fatalIf(err.Trace(srcURL), "Unable to stat source ‘"+newSrcURL+"’.") if srcContent.Type.IsRegular() { // Ellipses is supported only for folders. - fatalIf(errInvalidArgument.Trace(), "Source ‘"+srcURL+"’ is not a folder.") + fatalIf(errInvalidArgument().Trace(), "Source ‘"+srcURL+"’ is not a folder.") } if len(tgtURLs) == 0 && tgtURLs == nil { - fatalIf(errInvalidArgument.Trace(), "Invalid number of target arguments to mirror command.") + fatalIf(errInvalidArgument().Trace(), "Invalid number of target arguments to mirror command.") } for _, tgtURL := range tgtURLs { // Recursive URLs are not allowed in target. if isURLRecursive(tgtURL) { - fatalIf(errDummy.Trace(), fmt.Sprintf("Recursive option is not supported for target ‘%s’ argument.", tgtURL)) + fatalIf(errDummy().Trace(), fmt.Sprintf("Recursive option is not supported for target ‘%s’ argument.", tgtURL)) } url, e := client.Parse(tgtURL) @@ -109,14 +109,14 @@ func checkMirrorSyntax(ctx *cli.Context) { if url.Host != "" { if url.Path == string(url.Separator) { - fatalIf(errInvalidArgument.Trace(), fmt.Sprintf("Target ‘%s’ does not contain bucket name.", tgtURL)) + fatalIf(errInvalidArgument().Trace(), fmt.Sprintf("Target ‘%s’ does not contain bucket name.", tgtURL)) } } _, content, err := url2Stat(tgtURL) fatalIf(err.Trace(tgtURL), "Unable to stat target ‘"+tgtURL+"’.") if !content.Type.IsDir() { - fatalIf(errInvalidArgument.Trace(), "Target ‘"+tgtURL+"’ is not a folder.") + fatalIf(errInvalidArgument().Trace(), "Target ‘"+tgtURL+"’ is not a folder.") } } } diff --git a/session-main.go b/session-main.go index e1b7c136..03a49e93 100644 --- a/session-main.go +++ b/session-main.go @@ -93,7 +93,7 @@ func clearSession(sid string) { } if !isSession(sid) { - fatalIf(errDummy.Trace(), "Session ‘"+sid+"’ not found.") + fatalIf(errDummy().Trace(), "Session ‘"+sid+"’ not found.") } session, err := loadSessionV2(sid) @@ -144,7 +144,7 @@ func mainSession(ctx *cli.Context) { sid := strings.TrimSpace(ctx.Args().Tail().First()) if !isSession(sid) { - fatalIf(errDummy.Trace(), "Session ‘"+sid+"’ not found.") + fatalIf(errDummy().Trace(), "Session ‘"+sid+"’ not found.") } s, err := loadSessionV2(sid) diff --git a/session-v2.go b/session-v2.go index e67e7133..7092c590 100644 --- a/session-v2.go +++ b/session-v2.go @@ -209,7 +209,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, errInvalidArgument.Trace() + return nil, errInvalidArgument().Trace() } sessionFile, err := getSessionFile(sid) if err != nil { @@ -255,7 +255,7 @@ func isCopiedFactory(lastCopied string) func(string) bool { copied := true // closure return func(sourceURL string) bool { if sourceURL == "" { - fatalIf(errInvalidArgument.Trace(), "Empty source argument passed.") + fatalIf(errInvalidArgument().Trace(), "Empty source argument passed.") } if lastCopied == "" { return false diff --git a/typed-errors.go b/typed-errors.go index e39890b8..ea19ba96 100644 --- a/typed-errors.go +++ b/typed-errors.go @@ -23,9 +23,15 @@ import ( ) var ( - errDummy = probe.NewError(errors.New("")).Untrace() - errInvalidArgument = probe.NewError(errors.New("Invalid arguments provided, cannot proceed.")).Untrace() - errSourceListEmpty = probe.NewError(errors.New("Source argument list is empty.")).Untrace() + errDummy = func() *probe.Error { + return probe.NewError(errors.New("")).Untrace() + } + errInvalidArgument = func() *probe.Error { + return probe.NewError(errors.New("Invalid arguments provided, cannot proceed.")).Untrace() + } + errSourceListEmpty = func() *probe.Error { + return probe.NewError(errors.New("Source argument list is empty.")).Untrace() + } ) type eInvalidGlobURL struct { diff --git a/verify-runtime.go b/verify-runtime.go index 9a882503..af0e2fa6 100644 --- a/verify-runtime.go +++ b/verify-runtime.go @@ -91,7 +91,7 @@ func checkGolangRuntimeVersion() { v1 := newVersion(getNormalizedGolangVersion()) v2 := newVersion(minGolangVersion) if v1.LessThan(v2) { - errorIf(errDummy.Trace(), + errorIf(errDummy().Trace(), "Old Golang runtime version ‘"+v1.String()+"’ detected., ‘mc’ requires minimum go1.5 or later.") } }