From 40ff9f10330bf84f527ccfc5c441e6eb8f6a0d52 Mon Sep 17 00:00:00 2001 From: "Anand Babu (AB) Periasamy" Date: Mon, 24 Aug 2015 04:06:28 -0700 Subject: [PATCH] re-vendorize probe and simplfy typed errors --- access-main.go | 4 +- aliases.go | 2 +- common-methods.go | 4 +- config-main.go | 13 ++-- config.go | 4 +- cp-url.go | 57 +++++++------- diff-main.go | 2 +- diff.go | 17 ++-- hostconfig.go | 4 +- main.go | 3 +- mirror-url.go | 15 ++-- session-main.go | 5 +- session-v2.go | 4 +- typed-errors.go | 78 +++++++++---------- url.go | 2 +- vendor.json | 4 +- .../github.com/minio/minio/pkg/probe/probe.go | 7 +- verify-runtime.go | 3 +- version-main.go | 4 +- 19 files changed, 112 insertions(+), 120 deletions(-) diff --git a/access-main.go b/access-main.go index 157933ae..46b74e89 100644 --- a/access-main.go +++ b/access-main.go @@ -17,8 +17,6 @@ package main import ( - "errors" - "github.com/minio/cli" "github.com/minio/mc/pkg/client" "github.com/minio/minio/pkg/probe" @@ -66,7 +64,7 @@ func mainAccess(ctx *cli.Context) { config := mustGetMcConfig() acl := bucketACL(ctx.Args().First()) if !acl.isValidBucketACL() { - fatalIf(probe.NewError(errors.New("")), + fatalIf(errDummy.Trace(), "Unrecognized permission ‘"+acl.String()+"’. Allowed values are [private, public, readonly].") } for _, arg := range ctx.Args().Tail() { diff --git a/aliases.go b/aliases.go index 4bb0ff05..43324eec 100644 --- a/aliases.go +++ b/aliases.go @@ -74,7 +74,7 @@ func aliasExpand(aliasedURL string, aliases map[string]string) (string, *probe.E trimmedURL := expandedURL + "/" + strings.TrimPrefix(strings.TrimPrefix(splits[1], "/"), "\\") u, err := client.Parse(trimmedURL) if err != nil { - return aliasedURL, probe.NewError(errInvalidURL{URL: aliasedURL}) + return aliasedURL, probe.NewError(eInvalidURL{URL: aliasedURL}) } return u.String(), nil } diff --git a/common-methods.go b/common-methods.go index 1a890de2..9f1bc3f5 100644 --- a/common-methods.go +++ b/common-methods.go @@ -165,7 +165,7 @@ func getNewClient(urlStr string, auth hostConfig) (client.Client, *probe.Error) case client.Filesystem: return fs.New(urlStr) } - return nil, probe.NewError(errInitClient{url: urlStr}) + return nil, probe.NewError(eInitClient{URL: urlStr}) } // url2Stat - Returns client, config and its stat Content from the URL @@ -199,7 +199,7 @@ func isValidURL(url string) bool { func url2Client(url string) (client.Client, *probe.Error) { if !isValidURL(url) { - return nil, probe.NewError(errInvalidURL{URL: url}) + return nil, probe.NewError(eInvalidURL{URL: url}) } urlconfig, err := getHostConfig(url) if err != nil { diff --git a/config-main.go b/config-main.go index 066967d5..994a65dd 100644 --- a/config-main.go +++ b/config-main.go @@ -18,7 +18,6 @@ package main import ( "encoding/json" - "errors" "fmt" "strings" @@ -96,7 +95,7 @@ func mainConfig(ctx *cli.Context) { arg := ctx.Args().First() tailArgs := ctx.Args().Tail() if len(tailArgs) > 2 { - fatalIf(probe.NewError(errors.New("")), "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 { @@ -130,7 +129,7 @@ func mainConfig(ctx *cli.Context) { // addAlias - add new aliases func addAlias(alias, url string) { if alias == "" || url == "" { - fatalIf(probe.NewError(errors.New("")), "Alias or URL cannot be empty.") + fatalIf(errDummy.Trace(), "Alias or URL cannot be empty.") } conf := newConfigV2() config, err := quick.New(conf) @@ -141,18 +140,18 @@ func addAlias(alias, url string) { url = strings.TrimSuffix(url, "/") if !strings.HasPrefix(url, "http") { - fatalIf(probe.NewError(errors.New("")), 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(probe.NewError(errors.New("")), 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(probe.NewError(errors.New("")), 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(probe.NewError(errors.New("")), 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 dd957122..1ffeaf86 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, probe.NewError(errInvalidArgument) + 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 probe.NewError(errInvalidArgument) + return errInvalidArgument.Trace() } err := createMcConfigDir() if err != nil { diff --git a/cp-url.go b/cp-url.go index 337f9633..3dbd0be8 100644 --- a/cp-url.go +++ b/cp-url.go @@ -17,7 +17,6 @@ package main import ( - "errors" "fmt" "path/filepath" "strings" @@ -72,7 +71,7 @@ func checkCopySyntax(ctx *cli.Context) { /****** Generic rules *******/ // Recursive URLs are not allowed in target. if isURLRecursive(tgtURL) { - fatalIf(probe.NewError(errors.New("")), 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 { @@ -82,7 +81,7 @@ func checkCopySyntax(ctx *cli.Context) { } if url.Host != "" { if url.Path == string(url.Separator) { - fatalIf(probe.NewError(errInvalidArgument), fmt.Sprintf("Target ‘%s’ does not contain bucket name.", tgtURL)) + fatalIf(errInvalidArgument.Trace(), fmt.Sprintf("Target ‘%s’ does not contain bucket name.", tgtURL)) } } } @@ -96,14 +95,14 @@ func checkCopySyntax(ctx *cli.Context) { case copyURLsTypeD: // File | Folder... -> Folder. checkCopySyntaxTypeD(srcURLs, tgtURL) default: - fatalIf(probe.NewError(errInvalidArgument), "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(probe.NewError(errInvalidArgument), "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) @@ -111,34 +110,34 @@ func checkCopySyntaxTypeA(srcURLs []string, tgtURL string) { fatalIf(err.Trace(srcURL), "Unable to stat source ‘"+srcURL+"’.") if srcContent.Type.IsDir() { - fatalIf(probe.NewError(errInvalidArgument), 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(probe.NewError(errInvalidArgument), "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(probe.NewError(errInvalidArgument), "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(probe.NewError(errInvalidArgument), 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(probe.NewError(errInvalidArgument), "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(probe.NewError(errInvalidArgument), "Target ‘"+tgtURL+"’ is not a folder.") + fatalIf(errInvalidArgument.Trace(), "Target ‘"+tgtURL+"’ is not a folder.") } } } @@ -146,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(probe.NewError(errInvalidArgument), "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) @@ -154,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(probe.NewError(errInvalidArgument), "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(probe.NewError(errInvalidArgument), "Target ‘"+tgtURL+"’ is not a folder.") + fatalIf(errInvalidArgument.Trace(), "Target ‘"+tgtURL+"’ is not a folder.") } } } @@ -174,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(probe.NewError(errInvalidArgument), "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(probe.NewError(errInvalidArgument), 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(probe.NewError(errInvalidArgument), "Source ‘"+srcURL+"’ is not a file.") + fatalIf(errInvalidArgument.Trace(), "Source ‘"+srcURL+"’ is not a file.") } } } @@ -192,7 +191,7 @@ func checkCopySyntaxTypeD(srcURLs []string, tgtURL string) { // Target exist?. if err == nil { if !tgtContent.Type.IsDir() { - fatalIf(probe.NewError(errInvalidArgument), "Target ‘"+tgtURL+"’ is not a folder.") + fatalIf(errInvalidArgument.Trace(), "Target ‘"+tgtURL+"’ is not a folder.") } } } @@ -237,7 +236,7 @@ func prepareCopyURLsTypeA(sourceURL string, targetURL string) copyURLs { } if !sourceContent.Type.IsRegular() { // Source is not a regular file - return copyURLs{Error: probe.NewError(errInvalidSource{URL: sourceURL})} + return copyURLs{Error: probe.NewError(eInvalidSource{URL: sourceURL})} } // All OK.. We can proceed. Type A sourceContent.Name = sourceURL @@ -254,19 +253,19 @@ func prepareCopyURLsTypeB(sourceURL string, targetURL string) copyURLs { } if !sourceContent.Type.IsRegular() { // Source is not a regular file. - return copyURLs{Error: probe.NewError(errInvalidSource{URL: sourceURL})} + return copyURLs{Error: probe.NewError(eInvalidSource{URL: sourceURL})} } // All OK.. We can proceed. Type B: source is a file, target is a folder and exists. { sourceURLParse, err := client.Parse(sourceURL) if err != nil { - return copyURLs{Error: probe.NewError(errInvalidSource{URL: sourceURL})} + return copyURLs{Error: probe.NewError(eInvalidSource{URL: sourceURL})} } targetURLParse, err := client.Parse(targetURL) if err != nil { - return copyURLs{Error: probe.NewError(errInvalidTarget{URL: targetURL})} + return copyURLs{Error: probe.NewError(eInvalidTarget{URL: targetURL})} } targetURLParse.Path = filepath.Join(targetURLParse.Path, filepath.Base(sourceURLParse.Path)) return prepareCopyURLsTypeA(sourceURL, targetURLParse.String()) @@ -281,7 +280,7 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs { defer close(copyURLsCh) if !isURLRecursive(sourceURL) { // Source is not of recursive type. - copyURLsCh <- copyURLs{Error: probe.NewError(errSourceNotRecursive{URL: sourceURL})} + copyURLsCh <- copyURLs{Error: probe.NewError(eSourceNotRecursive{URL: sourceURL})} return } @@ -296,7 +295,7 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs { if !sourceContent.Type.IsDir() { // Source is not a dir. - copyURLsCh <- copyURLs{Error: probe.NewError(errSourceIsNotDir{URL: sourceURL})} + copyURLsCh <- copyURLs{Error: probe.NewError(eSourceIsNotDir{URL: sourceURL})} return } @@ -315,13 +314,13 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs { // All OK.. We can proceed. Type B: source is a file, target is a folder and exists. sourceURLParse, err := client.Parse(sourceURL) if err != nil { - copyURLsCh <- copyURLs{Error: probe.NewError(errInvalidSource{URL: sourceURL})} + copyURLsCh <- copyURLs{Error: probe.NewError(eInvalidSource{URL: sourceURL})} continue } targetURLParse, err := client.Parse(targetURL) if err != nil { - copyURLsCh <- copyURLs{Error: probe.NewError(errInvalidTarget{URL: targetURL})} + copyURLsCh <- copyURLs{Error: probe.NewError(eInvalidTarget{URL: targetURL})} continue } @@ -331,7 +330,7 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs { sourceContentURL := sourceURLDelimited + sourceContentName sourceContentParse, err := client.Parse(sourceContentURL) if err != nil { - copyURLsCh <- copyURLs{Error: probe.NewError(errInvalidSource{URL: sourceContentName})} + copyURLsCh <- copyURLs{Error: probe.NewError(eInvalidSource{URL: sourceContentName})} continue } @@ -353,7 +352,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: errSourceListEmpty.Trace()} return } @@ -391,7 +390,7 @@ func prepareCopyURLs(sourceURLs []string, targetURL string) <-chan copyURLs { copyURLsCh <- cURLs } default: - copyURLsCh <- copyURLs{Error: probe.NewError(errInvalidArgument)} + copyURLsCh <- copyURLs{Error: errInvalidArgument.Trace()} } }(sourceURLs, targetURL, copyURLsCh) diff --git a/diff-main.go b/diff-main.go index e9e2547c..9c3bd44e 100644 --- a/diff-main.go +++ b/diff-main.go @@ -74,7 +74,7 @@ func mainDiff(ctx *cli.Context) { fatalIf(err.Trace(secondArg), "Unable to parse second argument ‘"+secondArg+"’.") if isURLRecursive(secondURL) { - fatalIf(probe.NewError(errInvalidArgument), "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 ce770878..8425f7c1 100644 --- a/diff.go +++ b/diff.go @@ -18,7 +18,6 @@ package main import ( "encoding/json" - "errors" "os" "path/filepath" "strings" @@ -65,7 +64,7 @@ func (d DiffMessage) String() string { case "size": msg = "‘" + d.FirstURL + "’" + " and " + "‘" + d.SecondURL + "’" + " - differ in size." default: - fatalIf(probe.NewError(errors.New("")), "Unhandled difference between ‘"+d.FirstURL+"’ and ‘"+d.SecondURL+"’.") + fatalIf(errDummy.Trace(), "Unhandled difference between ‘"+d.FirstURL+"’ and ‘"+d.SecondURL+"’.") } return console.Colorize("Diff", msg) } @@ -77,13 +76,13 @@ func (d DiffMessage) String() string { // urlJoinPath Join a path to existing URL func urlJoinPath(url1, url2 string) (string, *probe.Error) { - u1, err := client.Parse(url1) - if err != nil { - return "", probe.NewError(err) + u1, e := client.Parse(url1) + if e != nil { + return "", probe.NewError(e) } - u2, err := client.Parse(url2) - if err != nil { - return "", probe.NewError(err) + u2, e := client.Parse(url2) + if e != nil { + return "", probe.NewError(e) } u1.Path = filepath.Join(u1.Path, u2.Path) return u1.String(), nil @@ -173,7 +172,7 @@ func doDiffObjects(firstURL, secondURL string, ch chan DiffMessage) { } default: ch <- DiffMessage{ - Error: probe.NewError(errNotAnObject{url: firstURL}), + Error: probe.NewError(eNotAnObject{URL: firstURL}), } return } diff --git a/hostconfig.go b/hostconfig.go index 6c3ca0ae..d6d744c5 100644 --- a/hostconfig.go +++ b/hostconfig.go @@ -50,12 +50,12 @@ func getHostConfig(URL string) (hostConfig, *probe.Error) { for globURL, hostCfg := range config.Hosts { match, err := filepath.Match(globURL, url.Host) if err != nil { - return hostConfig{}, probe.NewError(errInvalidGlobURL{glob: globURL, request: URL}) + return hostConfig{}, probe.NewError(eInvalidGlobURL{glob: globURL, request: URL}) } if match { return hostCfg, nil } } } - return hostConfig{}, probe.NewError(errNoMatchingHost{url: URL}) + return hostConfig{}, probe.NewError(eNoMatchingHost{URL: URL}) } diff --git a/main.go b/main.go index 9b535f27..388b4ddb 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,6 @@ package main import ( - "errors" "fmt" "net/http" "os" @@ -150,7 +149,7 @@ VERSION: {{end}} ` app.CommandNotFound = func(ctx *cli.Context, command string) { - fatalIf(probe.NewError(errors.New("")), 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 b96bbbdb..e6c9149e 100644 --- a/mirror-url.go +++ b/mirror-url.go @@ -18,7 +18,6 @@ package main import ( "encoding/json" - "errors" "fmt" "path/filepath" "strings" @@ -84,7 +83,7 @@ func checkMirrorSyntax(ctx *cli.Context) { /****** Generic rules *******/ // Source cannot be a folder (except when recursive) if !isURLRecursive(srcURL) { - fatalIf(probe.NewError(errInvalidArgument), 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) @@ -92,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(probe.NewError(errInvalidArgument), "Source ‘"+srcURL+"’ is not a folder.") + fatalIf(errInvalidArgument.Trace(), "Source ‘"+srcURL+"’ is not a folder.") } if len(tgtURLs) == 0 && tgtURLs == nil { - fatalIf(probe.NewError(errInvalidArgument), "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(probe.NewError(errors.New("")), 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) @@ -110,14 +109,14 @@ func checkMirrorSyntax(ctx *cli.Context) { if url.Host != "" { if url.Path == string(url.Separator) { - fatalIf(probe.NewError(errInvalidArgument), 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(probe.NewError(errInvalidArgument), "Target ‘"+tgtURL+"’ is not a folder.") + fatalIf(errInvalidArgument.Trace(), "Target ‘"+tgtURL+"’ is not a folder.") } } } @@ -216,7 +215,7 @@ func prepareMirrorURLs(sourceURL string, targetURLs []string) <-chan mirrorURLs } // if one of the targets is not dir exit if !targetContent.Type.IsDir() { - mirrorURLsCh <- mirrorURLs{Error: probe.NewError(errInvalidTarget{URL: targetURL})} + mirrorURLsCh <- mirrorURLs{Error: probe.NewError(eInvalidTarget{URL: targetURL})} return } // special case, be extremely careful before changing this behavior - will lead to data loss diff --git a/session-main.go b/session-main.go index d0992b6d..12c0def5 100644 --- a/session-main.go +++ b/session-main.go @@ -17,7 +17,6 @@ package main import ( - "errors" "os" "sort" "strings" @@ -93,7 +92,7 @@ func clearSession(sid string) { } if !isSession(sid) { - fatalIf(probe.NewError(errors.New("")), "Session ‘"+sid+"’ not found.") + fatalIf(errDummy.Trace(), "Session ‘"+sid+"’ not found.") } session, err := loadSessionV2(sid) @@ -138,7 +137,7 @@ func mainSession(ctx *cli.Context) { sid := strings.TrimSpace(ctx.Args().Tail().First()) if !isSession(sid) { - fatalIf(probe.NewError(errors.New("")), "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 3af6ae83..17de62b8 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, probe.NewError(errInvalidArgument) + 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(probe.NewError(errInvalidArgument), "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 784c63fb..e39890b8 100644 --- a/typed-errors.go +++ b/typed-errors.go @@ -16,73 +16,73 @@ package main -import "errors" +import ( + "errors" -type errNotAnObject struct { - url string -} + "github.com/minio/minio/pkg/probe" +) -func (e errNotAnObject) Error() string { - return "URL: ‘" + e.url + "’ not an object" -} +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() +) -var errInvalidArgument = errors.New("Invalid arguments provided, cannot proceed.") - -type errInvalidGlobURL struct { +type eInvalidGlobURL struct { glob string request string } -func (e errInvalidGlobURL) Error() string { +func (e eInvalidGlobURL) Error() string { return "Error reading glob URL ‘" + e.glob + "’ while comparing with ‘" + e.request + "’." } -type errNoMatchingHost struct { - url string -} - -func (e errNoMatchingHost) Error() string { - return "No matching host found for the given url ‘" + e.url + "’." -} - -type errInitClient struct { - url string -} - -func (e errInitClient) Error() string { - return "Unable to initialize client for url ‘" + e.url + "’." -} - -type errInvalidURL struct { +type eInvalidURL struct { URL string } -func (e errInvalidURL) Error() string { - return "Invalid url " + e.URL +func (e eInvalidURL) Error() string { + return "Invalid URL " + e.URL } -type errInvalidSource errInvalidURL +type eNoMatchingHost eInvalidURL -func (e errInvalidSource) Error() string { +func (e eNoMatchingHost) Error() string { + return "No matching host found for the given URL ‘" + e.URL + "’." +} + +type eInitClient eInvalidURL + +func (e eInitClient) Error() string { + return "Unable to initialize client for URL ‘" + e.URL + "’." +} + +type eInvalidSource eInvalidURL + +func (e eInvalidSource) Error() string { return "Invalid source " + e.URL } -type errInvalidTarget errInvalidURL +type eInvalidTarget eInvalidURL -func (e errInvalidTarget) Error() string { +func (e eInvalidTarget) Error() string { return "Invalid target " + e.URL } -type errSourceNotRecursive errInvalidURL +type eSourceNotRecursive eInvalidURL -func (e errSourceNotRecursive) Error() string { +func (e eSourceNotRecursive) Error() string { return "Source ‘" + e.URL + "’ is not recursive." } -type errSourceIsNotDir errInvalidURL +type eSourceIsNotDir eInvalidURL -func (e errSourceIsNotDir) Error() string { +func (e eSourceIsNotDir) Error() string { return "Source ‘" + e.URL + "’ is not a folder." } -var errSourceListEmpty = errors.New("Source list is empty.") +type eNotAnObject eInvalidURL + +func (e eNotAnObject) Error() string { + return "‘" + e.URL + "’ is not an object." +} diff --git a/url.go b/url.go index 29cfa2a4..0d29b54d 100644 --- a/url.go +++ b/url.go @@ -54,7 +54,7 @@ func getCanonicalizedURL(arg string, aliases map[string]string) (urlStr string, } if _, err := client.Parse(urlStr); err != nil { // Not a valid URL. Return error - return "", probe.NewError(errInvalidURL{urlStr}) + return "", probe.NewError(eInvalidURL{urlStr}) } return urlStr, nil } diff --git a/vendor.json b/vendor.json index 651829a3..05a099af 100755 --- a/vendor.json +++ b/vendor.json @@ -48,8 +48,8 @@ "canonical": "github.com/minio/minio/pkg/probe", "comment": "", "local": "vendor/github.com/minio/minio/pkg/probe", - "revision": "4d1f38d28cabcfa321e9d88acef67e16e7bafb2a", - "revisionTime": "2015-08-22T18:37:56-07:00" + "revision": "2f260adc69701f89a38fc8a27cde4b868dfe9ddf", + "revisionTime": "2015-08-24T03:43:13-07:00" }, { "canonical": "github.com/minio/minio/pkg/quick", diff --git a/vendor/github.com/minio/minio/pkg/probe/probe.go b/vendor/github.com/minio/minio/pkg/probe/probe.go index a7872a8a..5a30c319 100644 --- a/vendor/github.com/minio/minio/pkg/probe/probe.go +++ b/vendor/github.com/minio/minio/pkg/probe/probe.go @@ -108,18 +108,19 @@ func (e *Error) trace(fields ...string) *Error { } // Untrace erases last trace entry. -func (e *Error) Untrace() { +func (e *Error) Untrace() *Error { if e == nil { - return + return nil } e.lock.Lock() defer e.lock.Unlock() l := len(e.CallTrace) if l == 0 { - return + return nil } e.CallTrace = e.CallTrace[:l-1] + return e } // ToGoError returns original error message. diff --git a/verify-runtime.go b/verify-runtime.go index 3a0fe082..9a882503 100644 --- a/verify-runtime.go +++ b/verify-runtime.go @@ -17,7 +17,6 @@ package main import ( - "errors" "fmt" "regexp" "runtime" @@ -92,7 +91,7 @@ func checkGolangRuntimeVersion() { v1 := newVersion(getNormalizedGolangVersion()) v2 := newVersion(minGolangVersion) if v1.LessThan(v2) { - errorIf(probe.NewError(errors.New("")), + errorIf(errDummy.Trace(), "Old Golang runtime version ‘"+v1.String()+"’ detected., ‘mc’ requires minimum go1.5 or later.") } } diff --git a/version-main.go b/version-main.go index 86269093..c1435d1c 100644 --- a/version-main.go +++ b/version-main.go @@ -58,12 +58,12 @@ func mainVersion(ctxx *cli.Context) { Format string `json:"format"` } if globalJSONFlag { - tB, err := json.Marshal( + tB, e := json.Marshal( struct { Version Version `json:"version"` }{Version: Version{t, "RFC3339Nano"}}, ) - fatalIf(probe.NewError(err), "Unable to construct version string.") + fatalIf(probe.NewError(e), "Unable to construct version string.") console.Println(string(tB)) return }