diff --git a/access-main.go b/access-main.go index 2b699de6..6da1d674 100644 --- a/access-main.go +++ b/access-main.go @@ -64,7 +64,7 @@ func runAccessCmd(ctx *cli.Context) { config := mustGetMcConfig() acl := bucketACL(ctx.Args().First()) if !acl.isValidBucketACL() { - Fatal(probe.New(errInvalidACL{acl: acl.String()})) + Fatal(probe.NewError(errInvalidACL{acl: acl.String()})) } for _, arg := range ctx.Args().Tail() { targetURL, err := getExpandedURL(arg, config.Aliases) diff --git a/aliases.go b/aliases.go index 4dfcd28c..a61ff680 100644 --- a/aliases.go +++ b/aliases.go @@ -49,7 +49,7 @@ func isValidAliasName(aliasName string) bool { func aliasExpand(aliasedURL string, aliases map[string]string) (string, *probe.Error) { u, err := client.Parse(aliasedURL) if err != nil { - return aliasedURL, probe.New(errInvalidURL{URL: aliasedURL}) + return aliasedURL, probe.NewError(errInvalidURL{URL: aliasedURL}) } // proper URL if u.Host != "" { @@ -69,7 +69,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.New(errInvalidURL{URL: aliasedURL}) + return aliasedURL, probe.NewError(errInvalidURL{URL: aliasedURL}) } return u.String(), nil } diff --git a/cat-main.go b/cat-main.go index aece0f9b..0cdfce8b 100644 --- a/cat-main.go +++ b/cat-main.go @@ -92,9 +92,9 @@ func doCatCmd(sourceURL string) *probe.Error { // stdout closed by the user. Gracefully exit. return nil } - return probe.New(err) + return probe.NewError(err) default: - return probe.New(err) + return probe.NewError(err) } } return nil diff --git a/common-methods.go b/common-methods.go index 03fb06b2..27c79424 100644 --- a/common-methods.go +++ b/common-methods.go @@ -140,7 +140,7 @@ func putTargets(targetURLs []string, length int64, reader io.Reader) *probe.Erro func getNewClient(urlStr string, auth hostConfig) (client.Client, *probe.Error) { url, err := client.Parse(urlStr) if err != nil { - return nil, probe.New(err) + return nil, probe.NewError(err) } switch url.Type { case client.Object: // Minio and S3 compatible cloud storage @@ -166,7 +166,7 @@ func getNewClient(urlStr string, auth hostConfig) (client.Client, *probe.Error) case client.Filesystem: return fs.New(urlStr) } - return nil, probe.New(errInvalidURL{URL: urlStr}) + return nil, probe.NewError(errInvalidURL{URL: urlStr}) } // url2Stat - Returns client, config and its stat Content from the URL @@ -200,7 +200,7 @@ func isValidURL(url string) bool { func url2Client(url string) (client.Client, *probe.Error) { if !isValidURL(url) { - return nil, probe.New(errInvalidURL{URL: url}) + return nil, probe.NewError(errInvalidURL{URL: url}) } urlconfig, err := getHostConfig(url) if err != nil { diff --git a/config-main.go b/config-main.go index 597eb8d4..25afdb1c 100644 --- a/config-main.go +++ b/config-main.go @@ -81,7 +81,7 @@ func saveConfig(arg string, aliases []string) *probe.Error { } return writeConfig(config) default: - return probe.New(errInvalidArgument{}) + return probe.NewError(errInvalidArgument{}) } } @@ -113,13 +113,13 @@ func doConfig(arg string, aliases []string) (string, *probe.Error) { if arg == "alias" { return "Alias written to [" + configPath + "].", nil } - return "", probe.New(errUnexpected{}) + return "", probe.NewError(errUnexpected{}) } // addAlias - add new aliases func addAlias(aliases []string) (quick.Config, *probe.Error) { if len(aliases) < 2 { - return nil, probe.New(errInvalidArgument{}) + return nil, probe.NewError(errInvalidArgument{}) } conf := newConfigV1() config, err := quick.New(conf) @@ -134,18 +134,18 @@ func addAlias(aliases []string) (quick.Config, *probe.Error) { aliasName := aliases[0] url := strings.TrimSuffix(aliases[1], "/") if strings.HasPrefix(aliasName, "http") { - return nil, probe.New(errInvalidAliasName{name: aliasName}) + return nil, probe.NewError(errInvalidAliasName{name: aliasName}) } if !strings.HasPrefix(url, "http") { - return nil, probe.New(errInvalidURL{URL: url}) + return nil, probe.NewError(errInvalidURL{URL: url}) } if !isValidAliasName(aliasName) { - return nil, probe.New(errInvalidAliasName{name: aliasName}) + return nil, probe.NewError(errInvalidAliasName{name: aliasName}) } // convert interface{} back to its original struct newConf := config.Data().(*configV1) if _, ok := newConf.Aliases[aliasName]; ok { - return nil, probe.New(errAliasExists{}) + return nil, probe.NewError(errAliasExists{}) } newConf.Aliases[aliasName] = url newConfig, err := quick.New(newConf) diff --git a/config.go b/config.go index c28411c8..8a9cd3e8 100644 --- a/config.go +++ b/config.go @@ -52,7 +52,7 @@ func getMcConfigDir() (string, *probe.Error) { } u, err := user.Current() if err != nil { - return "", probe.New(err) + return "", probe.NewError(err) } // For windows the path is slightly different switch runtime.GOOS { @@ -77,7 +77,7 @@ func createMcConfigDir() *probe.Error { return err.Trace() } if err := os.MkdirAll(p, 0700); err != nil { - return probe.New(err) + return probe.NewError(err) } return nil } @@ -101,7 +101,7 @@ func mustGetMcConfigPath() string { // getMcConfig - reads configuration file and returns config func getMcConfig() (*configV1, *probe.Error) { if !isMcConfigExists() { - return nil, probe.New(errInvalidArgument{}) + return nil, probe.NewError(errInvalidArgument{}) } configFile, err := getMcConfigPath() diff --git a/cp-url.go b/cp-url.go index 39025f7e..6ea89f82 100644 --- a/cp-url.go +++ b/cp-url.go @@ -73,13 +73,13 @@ 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.New(errInvalidArgument{})) + console.Fatalf("Recursive option is not supported for target ‘%s’ argument. %s\n", tgtURL, probe.NewError(errInvalidArgument{})) } // scope locally { url, err := client.Parse(tgtURL) if err != nil { - console.Fatalf("Unable to parse target ‘%s’ argument. %s\n", tgtURL, probe.New(err)) + console.Fatalf("Unable to parse target ‘%s’ argument. %s\n", tgtURL, probe.NewError(err)) } if url.Host != "" { if url.Path == string(url.Separator) { @@ -104,7 +104,7 @@ 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.New(errInvalidArgument{})) + console.Fatalf("Invalid number of source arguments to copy command. %s\n", probe.NewError(errInvalidArgument{})) } srcURL := srcURLs[0] _, srcContent, err := url2Stat(srcURL) @@ -113,7 +113,7 @@ func checkCopySyntaxTypeA(srcURLs []string, tgtURL string) { 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() { - Fatal(probe.New(errSourceIsNotFile{URL: srcURL})) + Fatal(probe.NewError(errSourceIsNotFile{URL: srcURL})) } } @@ -129,14 +129,14 @@ func checkCopySyntaxTypeB(srcURLs []string, tgtURL string) { 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() { - Fatal(probe.New(errSourceIsNotFile{URL: srcURL})) + Fatal(probe.NewError(errSourceIsNotFile{URL: srcURL})) } _, tgtContent, err := url2Stat(tgtURL) // Target exist?. if err == nil { if !tgtContent.Type.IsDir() { - Fatal(probe.New(errTargetIsNotDir{URL: tgtURL})) + Fatal(probe.NewError(errTargetIsNotDir{URL: tgtURL})) } } } @@ -152,13 +152,13 @@ func checkCopySyntaxTypeC(srcURLs []string, tgtURL string) { Fatal(err) if srcContent.Type.IsRegular() { // Ellipses is supported only for folders. - Fatal(probe.New(errSourceIsNotDir{URL: srcURL})) + Fatal(probe.NewError(errSourceIsNotDir{URL: srcURL})) } _, tgtContent, err := url2Stat(tgtURL) // Target exist?. if err == nil { if !tgtContent.Type.IsDir() { - Fatal(probe.New(errTargetIsNotDir{URL: tgtURL})) + Fatal(probe.NewError(errTargetIsNotDir{URL: tgtURL})) } } } @@ -171,7 +171,7 @@ func checkCopySyntaxTypeD(srcURLs []string, tgtURL string) { _, srcContent, err := url2Stat(srcURL) Fatal(err) if !srcContent.Type.IsDir() { // Ellipses is supported only for folders. - Fatal(probe.New(errSourceIsNotDir{URL: srcURL})) + Fatal(probe.NewError(errSourceIsNotDir{URL: srcURL})) } } else { // Regular URL. _, srcContent, err := url2Stat(srcURL) @@ -180,7 +180,7 @@ func checkCopySyntaxTypeD(srcURLs []string, tgtURL string) { 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() { - Fatal(probe.New(errSourceIsNotFile{URL: srcURL})) + Fatal(probe.NewError(errSourceIsNotFile{URL: srcURL})) } } } @@ -188,7 +188,7 @@ func checkCopySyntaxTypeD(srcURLs []string, tgtURL string) { // Target exist?. if err == nil { if !tgtContent.Type.IsDir() { - Fatal(probe.New(errTargetIsNotDir{URL: tgtURL})) + Fatal(probe.NewError(errTargetIsNotDir{URL: tgtURL})) } } } @@ -233,7 +233,7 @@ func prepareCopyURLsTypeA(sourceURL string, targetURL string) copyURLs { } if !sourceContent.Type.IsRegular() { // Source is not a regular file - return copyURLs{Error: probe.New(errInvalidSource{URL: sourceURL})} + return copyURLs{Error: probe.NewError(errInvalidSource{URL: sourceURL})} } // All OK.. We can proceed. Type A sourceContent.Name = sourceURL @@ -250,19 +250,19 @@ func prepareCopyURLsTypeB(sourceURL string, targetURL string) copyURLs { } if !sourceContent.Type.IsRegular() { // Source is not a regular file. - return copyURLs{Error: probe.New(errInvalidSource{URL: sourceURL})} + return copyURLs{Error: probe.NewError(errInvalidSource{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.New(errInvalidSource{URL: sourceURL})} + return copyURLs{Error: probe.NewError(errInvalidSource{URL: sourceURL})} } targetURLParse, err := client.Parse(targetURL) if err != nil { - return copyURLs{Error: probe.New(errInvalidTarget{URL: targetURL})} + return copyURLs{Error: probe.NewError(errInvalidTarget{URL: targetURL})} } targetURLParse.Path = filepath.Join(targetURLParse.Path, filepath.Base(sourceURLParse.Path)) return prepareCopyURLsTypeA(sourceURL, targetURLParse.String()) @@ -277,7 +277,7 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs { defer close(copyURLsCh) if !isURLRecursive(sourceURL) { // Source is not of recursive type. - copyURLsCh <- copyURLs{Error: probe.New(errSourceNotRecursive{URL: sourceURL})} + copyURLsCh <- copyURLs{Error: probe.NewError(errSourceNotRecursive{URL: sourceURL})} return } @@ -292,7 +292,7 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs { if !sourceContent.Type.IsDir() { // Source is not a dir. - copyURLsCh <- copyURLs{Error: probe.New(errSourceIsNotDir{URL: sourceURL})} + copyURLsCh <- copyURLs{Error: probe.NewError(errSourceIsNotDir{URL: sourceURL})} return } @@ -311,13 +311,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.New(errInvalidSource{URL: sourceURL})} + copyURLsCh <- copyURLs{Error: probe.NewError(errInvalidSource{URL: sourceURL})} continue } targetURLParse, err := client.Parse(targetURL) if err != nil { - copyURLsCh <- copyURLs{Error: probe.New(errInvalidTarget{URL: targetURL})} + copyURLsCh <- copyURLs{Error: probe.NewError(errInvalidTarget{URL: targetURL})} continue } @@ -327,7 +327,7 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs { sourceContentURL := sourceURLDelimited + sourceContentName sourceContentParse, err := client.Parse(sourceContentURL) if err != nil { - copyURLsCh <- copyURLs{Error: probe.New(errInvalidSource{URL: sourceContentName})} + copyURLsCh <- copyURLs{Error: probe.NewError(errInvalidSource{URL: sourceContentName})} continue } @@ -349,7 +349,7 @@ func prepareCopyURLsTypeD(sourceURLs []string, targetURL string) <-chan copyURLs if sourceURLs == nil { // Source list is empty. - copyURLsCh <- copyURLs{Error: probe.New(errSourceListEmpty{})} + copyURLsCh <- copyURLs{Error: probe.NewError(errSourceListEmpty{})} return } @@ -387,7 +387,7 @@ func prepareCopyURLs(sourceURLs []string, targetURL string) <-chan copyURLs { copyURLsCh <- cURLs } default: - copyURLsCh <- copyURLs{Error: probe.New(errInvalidArgument{})} + copyURLsCh <- copyURLs{Error: probe.NewError(errInvalidArgument{})} } }(sourceURLs, targetURL, copyURLsCh) diff --git a/diff.go b/diff.go index 690f5b46..bfd2a76f 100644 --- a/diff.go +++ b/diff.go @@ -63,11 +63,11 @@ func mustURLJoinPath(url1, url2 string) string { func urlJoinPath(url1, url2 string) (string, *probe.Error) { u1, err := client.Parse(url1) if err != nil { - return "", probe.New(err) + return "", probe.NewError(err) } u2, err := client.Parse(url2) if err != nil { - return "", probe.New(err) + return "", probe.NewError(err) } u1.Path = filepath.Join(u1.Path, u2.Path) return u1.String(), nil @@ -170,7 +170,7 @@ func doDiffObjects(firstURL, secondURL string, ch chan diff) { default: ch <- diff{ message: "‘" + firstURL + "’ is not an object. Please report this bug with ‘--debug’ option.", - err: probe.New(errNotAnObject{url: firstURL}), + err: probe.NewError(errNotAnObject{url: firstURL}), } return } diff --git a/hostconfig.go b/hostconfig.go index d8f21dbd..34a5288d 100644 --- a/hostconfig.go +++ b/hostconfig.go @@ -37,7 +37,7 @@ func getHostConfig(URL string) (hostConfig, *probe.Error) { { url, err := client.Parse(URL) if err != nil { - return hostConfig{}, probe.New(err) + return hostConfig{}, probe.NewError(err) } // No host matching or keys needed for filesystem requests if url.Type == client.Filesystem { @@ -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.New(errInvalidGlobURL{glob: globURL, request: URL}) + return hostConfig{}, probe.NewError(errInvalidGlobURL{glob: globURL, request: URL}) } if match { return hostCfg, nil } } } - return hostConfig{}, probe.New(errNoMatchingHost{}) + return hostConfig{}, probe.NewError(errNoMatchingHost{}) } diff --git a/mirror-main.go b/mirror-main.go index 1f9c3419..bb9eafb3 100644 --- a/mirror-main.go +++ b/mirror-main.go @@ -161,7 +161,7 @@ func doPrepareMirrorURLs(session *sessionV2, trapCh <-chan bool) { jsonData, err := json.Marshal(sURLs) if err != nil { session.Close() - console.Fatalf("Unable to marshal URLs to JSON. %s\n", probe.New(err)) + console.Fatalf("Unable to marshal URLs to JSON. %s\n", probe.NewError(err)) } fmt.Fprintln(dataFP, string(jsonData)) scanBar(sURLs.SourceContent.Name) diff --git a/mirror-url.go b/mirror-url.go index 48e7e660..905d29f5 100644 --- a/mirror-url.go +++ b/mirror-url.go @@ -96,13 +96,13 @@ func checkMirrorSyntax(ctx *cli.Context) { Fatal(err) if srcContent.Type.IsRegular() { // Ellipses is supported only for folders. - Fatal(probe.New(errSourceIsNotDir{URL: srcURL})) + Fatal(probe.NewError(errSourceIsNotDir{URL: srcURL})) } for _, tgtURL := range tgtURLs { _, content, err := url2Stat(tgtURL) if err == nil { if !content.Type.IsDir() { - Fatal(probe.New(errTargetIsNotDir{URL: tgtURL})) + Fatal(probe.NewError(errTargetIsNotDir{URL: tgtURL})) } } } @@ -202,7 +202,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.New(errInvalidTarget{URL: targetURL})} + mirrorURLsCh <- mirrorURLs{Error: probe.NewError(errInvalidTarget{URL: targetURL})} return } // special case, be extremely careful before changing this behavior - will lead to data loss diff --git a/pkg/client/fs/fs.go b/pkg/client/fs/fs.go index ab7726fc..cc1e50fe 100644 --- a/pkg/client/fs/fs.go +++ b/pkg/client/fs/fs.go @@ -36,7 +36,7 @@ type fsClient struct { // New - instantiate a new fs client func New(path string) (client.Client, *probe.Error) { if strings.TrimSpace(path) == "" { - return nil, probe.New(client.EmptyPath{}) + return nil, probe.NewError(client.EmptyPath{}) } return &fsClient{path: normalizePath(path)}, nil } @@ -60,17 +60,17 @@ func (f *fsClient) fsStat() (os.FileInfo, *probe.Error) { // Resolve symlinks fpath, err := filepath.EvalSymlinks(fpath) if os.IsNotExist(err) { - return nil, probe.New(err) + return nil, probe.NewError(err) } if err != nil { - return nil, probe.New(err) + return nil, probe.NewError(err) } st, err := os.Stat(fpath) if os.IsNotExist(err) { - return nil, probe.New(client.NotFound{Path: fpath}) + return nil, probe.NewError(client.NotFound{Path: fpath}) } if err != nil { - return nil, probe.New(err) + return nil, probe.NewError(err) } return st, nil } @@ -81,12 +81,12 @@ func (f *fsClient) PutObject(size int64, data io.Reader) *probe.Error { objectPath := f.path if objectDir != "" { if err := os.MkdirAll(objectDir, 0700); err != nil { - return probe.New(err) + return probe.NewError(err) } } fs, err := os.Create(objectPath) if err != nil { - return probe.New(err) + return probe.NewError(err) } defer fs.Close() @@ -94,14 +94,14 @@ func (f *fsClient) PutObject(size int64, data io.Reader) *probe.Error { if size > 0 { _, err = io.CopyN(fs, data, int64(size)) if err != nil { - return probe.New(err) + return probe.NewError(err) } } else { // size could be 0 for virtual files on certain filesystems // for example /proc, so read till EOF for such files _, err = io.Copy(fs, data) if err != nil { - return probe.New(err) + return probe.NewError(err) } } return nil @@ -111,7 +111,7 @@ func (f *fsClient) PutObject(size int64, data io.Reader) *probe.Error { func (f *fsClient) get() (io.ReadCloser, int64, *probe.Error) { body, err := os.Open(f.path) if err != nil { - return nil, 0, probe.New(err) + return nil, 0, probe.NewError(err) } { content, err := f.getFSMetadata() @@ -123,7 +123,7 @@ func (f *fsClient) get() (io.ReadCloser, int64, *probe.Error) { } func (f *fsClient) PresignedGetObject(expires time.Duration, offset, length int64) (string, *probe.Error) { - return "", probe.New(client.APINotImplemented{API: "PresignedGetObject"}) + return "", probe.NewError(client.APINotImplemented{API: "PresignedGetObject"}) } // GetObject download an full or part object from bucket @@ -131,7 +131,7 @@ func (f *fsClient) PresignedGetObject(expires time.Duration, offset, length int6 // with errors getobject will return nil reader, length and typed errors func (f *fsClient) GetObject(offset, length int64) (io.ReadCloser, int64, *probe.Error) { if offset < 0 || length < 0 { - return nil, 0, probe.New(client.InvalidRange{Offset: offset}) + return nil, 0, probe.NewError(client.InvalidRange{Offset: offset}) } tmppath := f.path @@ -144,22 +144,22 @@ func (f *fsClient) GetObject(offset, length int64) (io.ReadCloser, int64, *probe // Resolve symlinks _, err := filepath.EvalSymlinks(tmppath) if os.IsNotExist(err) { - return nil, length, probe.New(err) + return nil, length, probe.NewError(err) } if err != nil { - return nil, length, probe.New(err) + return nil, length, probe.NewError(err) } if offset == 0 && length == 0 { return f.get() } body, err := os.Open(f.path) if err != nil { - return nil, length, probe.New(err) + return nil, length, probe.NewError(err) } _, err = io.CopyN(ioutil.Discard, body, int64(offset)) if err != nil { - return nil, length, probe.New(err) + return nil, length, probe.NewError(err) } return body, length, nil } @@ -191,14 +191,14 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) { if os.IsNotExist(err) { contentCh <- client.ContentOnChannel{ Content: nil, - Err: probe.New(err), + Err: probe.NewError(err), } return } if err != nil { contentCh <- client.ContentOnChannel{ Content: nil, - Err: probe.New(err), + Err: probe.NewError(err), } return } @@ -207,7 +207,7 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) { if err != nil { contentCh <- client.ContentOnChannel{ Content: nil, - Err: probe.New(err), + Err: probe.NewError(err), } return } @@ -223,7 +223,7 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) { if err != nil { contentCh <- client.ContentOnChannel{ Content: nil, - Err: probe.New(err), + Err: probe.NewError(err), } return } @@ -233,7 +233,7 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) { if err != nil { contentCh <- client.ContentOnChannel{ Content: nil, - Err: probe.New(err), + Err: probe.NewError(err), } return } @@ -244,14 +244,14 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) { if os.IsNotExist(err) { contentCh <- client.ContentOnChannel{ Content: nil, - Err: probe.New(client.ISBrokenSymlink{Path: file.Name()}), + Err: probe.NewError(client.ISBrokenSymlink{Path: file.Name()}), } continue } if err != nil { contentCh <- client.ContentOnChannel{ Content: nil, - Err: probe.New(err), + Err: probe.NewError(err), } continue } @@ -332,7 +332,7 @@ func (f *fsClient) listRecursiveInRoutine(contentCh chan client.ContentOnChannel if err != nil { contentCh <- client.ContentOnChannel{ Content: nil, - Err: probe.New(err), + Err: probe.NewError(err), } } } @@ -375,7 +375,7 @@ func aclToPerm(acl string) os.FileMode { func (f *fsClient) MakeBucket() *probe.Error { err := os.MkdirAll(f.path, 0775) if err != nil { - return probe.New(err) + return probe.NewError(err) } return nil } @@ -383,15 +383,15 @@ func (f *fsClient) MakeBucket() *probe.Error { // SetBucketACL - create a new bucket func (f *fsClient) SetBucketACL(acl string) *probe.Error { if !isValidBucketACL(acl) { - return probe.New(client.InvalidACLType{ACL: acl}) + return probe.NewError(client.InvalidACLType{ACL: acl}) } err := os.MkdirAll(f.path, aclToPerm(acl)) if err != nil { - return probe.New(err) + return probe.NewError(err) } err = os.Chmod(f.path, aclToPerm(acl)) if err != nil { - return probe.New(err) + return probe.NewError(err) } return nil } diff --git a/pkg/client/fs/fs_test.go b/pkg/client/fs/fs_test.go index b10f4a8b..dcac0544 100644 --- a/pkg/client/fs/fs_test.go +++ b/pkg/client/fs/fs_test.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package fs +package fs_test import ( "bytes" @@ -25,6 +25,7 @@ import ( "testing" "github.com/minio/mc/pkg/client" + "github.com/minio/mc/pkg/client/fs" . "gopkg.in/check.v1" ) @@ -40,7 +41,7 @@ func (s *MySuite) TestList(c *C) { defer os.RemoveAll(root) objectPath := filepath.Join(root, "object1") - fsc, perr := New(objectPath) + fsc, perr := fs.New(objectPath) c.Assert(err, IsNil) data := "hello" @@ -50,13 +51,13 @@ func (s *MySuite) TestList(c *C) { c.Assert(err, IsNil) objectPath = filepath.Join(root, "object2") - fsc, perr = New(objectPath) + fsc, perr = fs.New(objectPath) c.Assert(err, IsNil) perr = fsc.PutObject(int64(dataLen), bytes.NewReader([]byte(data))) c.Assert(err, IsNil) - fsc, perr = New(root) + fsc, perr = fs.New(root) c.Assert(err, IsNil) var contents []*client.Content @@ -75,13 +76,13 @@ func (s *MySuite) TestList(c *C) { } objectPath = filepath.Join(root, "test1/newObject1") - fsc, perr = New(objectPath) + fsc, perr = fs.New(objectPath) c.Assert(err, IsNil) perr = fsc.PutObject(int64(dataLen), bytes.NewReader([]byte(data))) c.Assert(err, IsNil) - fsc, perr = New(root) + fsc, perr = fs.New(root) c.Assert(err, IsNil) contents = nil @@ -103,7 +104,7 @@ func (s *MySuite) TestList(c *C) { c.Assert(content.Type.IsDir(), Equals, true) } - fsc, perr = New(root) + fsc, perr = fs.New(root) c.Assert(err, IsNil) contents = nil @@ -139,7 +140,7 @@ func (s *MySuite) TestPutBucket(c *C) { defer os.RemoveAll(root) bucketPath := filepath.Join(root, "bucket") - fsc, perr := New(bucketPath) + fsc, perr := fs.New(bucketPath) c.Assert(perr, IsNil) perr = fsc.MakeBucket() c.Assert(perr, IsNil) @@ -152,7 +153,7 @@ func (s *MySuite) TestStatBucket(c *C) { bucketPath := filepath.Join(root, "bucket") - fsc, perr := New(bucketPath) + fsc, perr := fs.New(bucketPath) c.Assert(perr, IsNil) perr = fsc.MakeBucket() c.Assert(perr, IsNil) @@ -166,7 +167,7 @@ func (s *MySuite) TestPutBucketACL(c *C) { defer os.RemoveAll(root) bucketPath := filepath.Join(root, "bucket") - fsc, perr := New(bucketPath) + fsc, perr := fs.New(bucketPath) c.Assert(perr, IsNil) perr = fsc.MakeBucket() c.Assert(perr, IsNil) @@ -181,7 +182,7 @@ func (s *MySuite) TestPutObject(c *C) { defer os.RemoveAll(root) objectPath := filepath.Join(root, "object") - fsc, perr := New(objectPath) + fsc, perr := fs.New(objectPath) c.Assert(perr, IsNil) data := "hello" @@ -197,7 +198,7 @@ func (s *MySuite) TestGetObject(c *C) { defer os.RemoveAll(root) objectPath := filepath.Join(root, "object") - fsc, perr := New(objectPath) + fsc, perr := fs.New(objectPath) c.Assert(perr, IsNil) data := "hello" @@ -221,7 +222,7 @@ func (s *MySuite) TestGetObjectRange(c *C) { defer os.RemoveAll(root) objectPath := filepath.Join(root, "object") - fsc, perr := New(objectPath) + fsc, perr := fs.New(objectPath) c.Assert(perr, IsNil) data := "hello world" @@ -244,7 +245,7 @@ func (s *MySuite) TestStatObject(c *C) { defer os.RemoveAll(root) objectPath := filepath.Join(root, "object") - fsc, perr := New(objectPath) + fsc, perr := fs.New(objectPath) c.Assert(perr, IsNil) data := "hello" diff --git a/pkg/client/s3/s3.go b/pkg/client/s3/s3.go index 383489fe..64b484d3 100644 --- a/pkg/client/s3/s3.go +++ b/pkg/client/s3/s3.go @@ -59,7 +59,7 @@ type s3Client struct { func New(config *Config) (client.Client, *probe.Error) { u, err := client.Parse(config.HostURL) if err != nil { - return nil, probe.New(err) + return nil, probe.NewError(err) } var transport http.RoundTripper switch { @@ -81,7 +81,7 @@ func New(config *Config) (client.Client, *probe.Error) { s3Conf.Endpoint = u.Scheme + u.SchemeSeparator + u.Host api, err := minio.New(s3Conf) if err != nil { - return nil, probe.New(err) + return nil, probe.NewError(err) } return &s3Client{api: api, hostURL: u}, nil } @@ -96,7 +96,7 @@ func (c *s3Client) GetObject(offset, length int64) (io.ReadCloser, int64, *probe bucket, object := c.url2BucketAndObject() reader, metadata, err := c.api.GetPartialObject(bucket, object, offset, length) if err != nil { - return nil, length, probe.New(err) + return nil, length, probe.NewError(err) } return reader, metadata.Size, nil } @@ -106,7 +106,7 @@ func (c *s3Client) PresignedGetObject(expires time.Duration, offset, length int6 bucket, object := c.url2BucketAndObject() presignedURL, err := c.api.PresignedGetPartialObject(bucket, object, expires, offset, length) if err != nil { - return "", probe.New(err) + return "", probe.NewError(err) } return presignedURL, nil } @@ -122,10 +122,10 @@ func (c *s3Client) PutObject(size int64, data io.Reader) *probe.Error { errResponse := minio.ToErrorResponse(err) if errResponse != nil { if errResponse.Code == "MethodNotAllowed" { - return probe.New(client.ObjectAlreadyExists{Object: object}) + return probe.NewError(client.ObjectAlreadyExists{Object: object}) } } - return probe.New(err) + return probe.NewError(err) } return nil } @@ -134,11 +134,11 @@ func (c *s3Client) PutObject(size int64, data io.Reader) *probe.Error { func (c *s3Client) MakeBucket() *probe.Error { bucket, object := c.url2BucketAndObject() if object != "" { - return probe.New(client.InvalidQueryURL{URL: c.hostURL.String()}) + return probe.NewError(client.InvalidQueryURL{URL: c.hostURL.String()}) } err := c.api.MakeBucket(bucket, minio.BucketACL("private")) if err != nil { - return probe.New(err) + return probe.NewError(err) } return nil } @@ -147,11 +147,11 @@ func (c *s3Client) MakeBucket() *probe.Error { func (c *s3Client) SetBucketACL(acl string) *probe.Error { bucket, object := c.url2BucketAndObject() if object != "" { - return probe.New(client.InvalidQueryURL{URL: c.hostURL.String()}) + return probe.NewError(client.InvalidQueryURL{URL: c.hostURL.String()}) } err := c.api.SetBucketACL(bucket, minio.BucketACL(acl)) if err != nil { - return probe.New(err) + return probe.NewError(err) } return nil } @@ -165,7 +165,7 @@ func (c *s3Client) Stat() (*client.Content, *probe.Error) { case bucket == "" && object == "": for bucket := range c.api.ListBuckets() { if bucket.Err != nil { - return nil, probe.New(bucket.Err) + return nil, probe.NewError(bucket.Err) } return &client.Content{Type: os.ModeDir}, nil } @@ -187,7 +187,7 @@ func (c *s3Client) Stat() (*client.Content, *probe.Error) { } } } - return nil, probe.New(err) + return nil, probe.NewError(err) } objectMetadata.Name = metadata.Key objectMetadata.Time = metadata.LastModified @@ -197,7 +197,7 @@ func (c *s3Client) Stat() (*client.Content, *probe.Error) { } err := c.api.BucketExists(bucket) if err != nil { - return nil, probe.New(err) + return nil, probe.NewError(err) } bucketMetadata := new(client.Content) bucketMetadata.Name = bucket @@ -253,7 +253,7 @@ func (c *s3Client) listInRoutine(contentCh chan client.ContentOnChannel) { if bucket.Err != nil { contentCh <- client.ContentOnChannel{ Content: nil, - Err: probe.New(bucket.Err), + Err: probe.NewError(bucket.Err), } return } @@ -285,7 +285,7 @@ func (c *s3Client) listInRoutine(contentCh chan client.ContentOnChannel) { if object.Err != nil { contentCh <- client.ContentOnChannel{ Content: nil, - Err: probe.New(object.Err), + Err: probe.NewError(object.Err), } return } @@ -323,7 +323,7 @@ func (c *s3Client) listRecursiveInRoutine(contentCh chan client.ContentOnChannel if bucket.Err != nil { contentCh <- client.ContentOnChannel{ Content: nil, - Err: probe.New(bucket.Err), + Err: probe.NewError(bucket.Err), } return } @@ -331,7 +331,7 @@ func (c *s3Client) listRecursiveInRoutine(contentCh chan client.ContentOnChannel if object.Err != nil { contentCh <- client.ContentOnChannel{ Content: nil, - Err: probe.New(object.Err), + Err: probe.NewError(object.Err), } return } @@ -351,7 +351,7 @@ func (c *s3Client) listRecursiveInRoutine(contentCh chan client.ContentOnChannel if object.Err != nil { contentCh <- client.ContentOnChannel{ Content: nil, - Err: probe.New(object.Err), + Err: probe.NewError(object.Err), } return } diff --git a/pkg/console/console.go b/pkg/console/console.go index 468c1b1f..246a7ebf 100644 --- a/pkg/console/console.go +++ b/pkg/console/console.go @@ -354,7 +354,7 @@ func Unlock() { // SetTheme sets a color theme func SetTheme(themeName string) *probe.Error { if !IsValidTheme(themeName) { - return probe.New(fmt.Errorf("Unsupported theme name [%s]", themeName)) + return probe.NewError(fmt.Errorf("Unsupported theme name [%s]", themeName)) } mutex.Lock() diff --git a/pkg/probe/probe.go b/pkg/probe/probe.go index ffab300f..ef283da2 100644 --- a/pkg/probe/probe.go +++ b/pkg/probe/probe.go @@ -66,11 +66,11 @@ type Error struct { tracePoints []tracePoint } -// New function instantiates an error probe for tracing. Original errors.error (golang's error +// NewError function instantiates an error probe for tracing. Original errors.error (golang's error // interface) is injected in only once during this New call. Rest of the time, you // trace the return path with Probe.Trace and finally handle reporting or quitting // at the top level. -func New(e error) *Error { +func NewError(e error) *Error { if e == nil { return nil } @@ -179,8 +179,38 @@ func (e *Error) JSON() string { return string(jBytes) } -// ToError returns original emnedded error. +// ToError returns original embedded error. func (e *Error) ToError() error { // No need to lock. "e.e" is set once during New and never changed. return e.e } + +// WrappedError implements container for *probe.Error +type WrappedError struct { + err *Error +} + +// NewWrappedError function wraps a *probe.Error into a 'error' compatible duck type +func NewWrappedError(err *Error) error { + return &WrappedError{err: err} +} + +// Error interface method +func (w *WrappedError) Error() string { + return w.err.String() +} + +// ToError get the *probe.Error embedded internally +func (w *WrappedError) ToError() *Error { + return w.err +} + +// ToWrappedError try to convert generic 'error' into typed *WrappedError, returns true if yes, false otherwise +func ToWrappedError(err error) (*WrappedError, bool) { + switch e := err.(type) { + case *WrappedError: + return e, true + default: + return nil, false + } +} diff --git a/pkg/probe/probe_test.go b/pkg/probe/probe_test.go index f50e8c63..a917d675 100644 --- a/pkg/probe/probe_test.go +++ b/pkg/probe/probe_test.go @@ -13,33 +13,41 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package probe +package probe_test import ( "os" "testing" + + "github.com/minio/mc/pkg/probe" + . "gopkg.in/check.v1" ) -func testDummy() *Error { - _, e := os.Stat("this-file-cannot-exit-234234232423423") - es := New(e) - es.Trace("this is hell", "asdf") +func Test(t *testing.T) { TestingT(t) } + +type MySuite struct{} + +var _ = Suite(&MySuite{}) + +func testDummy() *probe.Error { + _, e := os.Stat("this-file-cannot-exit") + es := probe.NewError(e) + es.Trace("Important info 1", "Import into 2") return es } -func TestProbe(t *testing.T) { +func (s *MySuite) TestProbe(c *C) { es := testDummy() - if es == nil { - t.Fail() - } + c.Assert(es, Not(Equals), nil) newES := es.Trace() - if newES == nil { - t.Fail() - } - /* - fmt.Println(es) - fmt.Println(es.JSON()) - fmt.Println(es.ToError()) - */ + c.Assert(newES, Not(Equals), nil) +} + +func (s *MySuite) TestWrappedError(c *C) { + _, e := os.Stat("this-file-cannot-exit") + es := probe.NewError(e) // *probe.Error + e = probe.NewWrappedError(es) // *probe.WrappedError + _, ok := probe.ToWrappedError(e) + c.Assert(ok, Equals, true) } diff --git a/pkg/quick/quick.go b/pkg/quick/quick.go index 08ef2415..9f9004ec 100644 --- a/pkg/quick/quick.go +++ b/pkg/quick/quick.go @@ -52,17 +52,17 @@ type config struct { // CheckData - checks the validity of config data. Data sould be of type struct and contain a string type field called "Version" func CheckData(data interface{}) *probe.Error { if !structs.IsStruct(data) { - return probe.New(fmt.Errorf("Invalid argument type. Expecing \"struct\" type.")) + return probe.NewError(fmt.Errorf("Invalid argument type. Expecing \"struct\" type.")) } st := structs.New(data) f, ok := st.FieldOk("Version") if !ok { - return probe.New(fmt.Errorf("Invalid type of struct argument. No [%s.Version] field found.", st.Name())) + return probe.NewError(fmt.Errorf("Invalid type of struct argument. No [%s.Version] field found.", st.Name())) } if f.Kind() != reflect.String { - return probe.New(fmt.Errorf("Invalid type of struct argument. Expecting \"string\" type [%s.Version] field.", st.Name())) + return probe.NewError(fmt.Errorf("Invalid type of struct argument. Expecting \"string\" type [%s.Version] field.", st.Name())) } return nil @@ -111,7 +111,7 @@ func (d config) Save(filename string) *probe.Error { jsonData, err := json.MarshalIndent(d.data, "", "\t") if err != nil { - return probe.New(err) + return probe.NewError(err) } if runtime.GOOS == "windows" { @@ -120,7 +120,7 @@ func (d config) Save(filename string) *probe.Error { err = ioutil.WriteFile(filename, jsonData, 0600) if err != nil { - return probe.New(err) + return probe.NewError(err) } return nil @@ -133,12 +133,12 @@ func (d *config) Load(filename string) *probe.Error { _, err := os.Stat(filename) if err != nil { - return probe.New(err) + return probe.NewError(err) } fileData, err := ioutil.ReadFile(filename) if err != nil { - return probe.New(err) + return probe.NewError(err) } if runtime.GOOS == "windows" { @@ -147,7 +147,7 @@ func (d *config) Load(filename string) *probe.Error { err = json.Unmarshal(fileData, (*d).data) if err != nil { - return probe.New(err) + return probe.NewError(err) } if err := CheckData(*(*d).data); err != nil { @@ -157,11 +157,11 @@ func (d *config) Load(filename string) *probe.Error { st := structs.New(*(*d).data) f, ok := st.FieldOk("Version") if !ok { - return probe.New(fmt.Errorf("Argument struct [%s] does not contain field \"Version\".", st.Name())) + return probe.NewError(fmt.Errorf("Argument struct [%s] does not contain field \"Version\".", st.Name())) } if (*d).Version() != f.Value() { - return probe.New(fmt.Errorf("Version mismatch")) + return probe.NewError(fmt.Errorf("Version mismatch")) } return nil diff --git a/pkg/quick/quick_test.go b/pkg/quick/quick_test.go index 84af748d..3db3ee8f 100644 --- a/pkg/quick/quick_test.go +++ b/pkg/quick/quick_test.go @@ -16,12 +16,13 @@ * limitations under the License. */ -package quick +package quick_test import ( "os" "testing" + "github.com/minio/mc/pkg/quick" . "gopkg.in/check.v1" ) @@ -32,7 +33,7 @@ type MySuite struct{} var _ = Suite(&MySuite{}) func (s *MySuite) TestCheckData(c *C) { - err := CheckData(nil) + err := quick.CheckData(nil) c.Assert(err, Not(IsNil)) type myStructBad struct { @@ -41,7 +42,7 @@ func (s *MySuite) TestCheckData(c *C) { Folders []string } saveMeBad := myStructBad{"guest", "nopassword", []string{"Work", "Documents", "Music"}} - err = CheckData(&saveMeBad) + err = quick.CheckData(&saveMeBad) c.Assert(err, Not(IsNil)) type myStructGood struct { @@ -52,7 +53,7 @@ func (s *MySuite) TestCheckData(c *C) { } saveMeGood := myStructGood{"1", "guest", "nopassword", []string{"Work", "Documents", "Music"}} - err = CheckData(&saveMeGood) + err = quick.CheckData(&saveMeGood) c.Assert(err, IsNil) } @@ -65,13 +66,13 @@ func (s *MySuite) TestSaveLoad(c *C) { Folders []string } saveMe := myStruct{"1", "guest", "nopassword", []string{"Work", "Documents", "Music"}} - config, err := New(&saveMe) + config, err := quick.New(&saveMe) c.Assert(err, IsNil) c.Assert(config, Not(IsNil)) config.Save("test.json") loadMe := myStruct{Version: "1"} - newConfig, err := New(&loadMe) + newConfig, err := quick.New(&loadMe) c.Assert(err, IsNil) c.Assert(newConfig, Not(IsNil)) newConfig.Load("test.json") @@ -91,7 +92,7 @@ func (s *MySuite) TestDiff(c *C) { Folders []string } saveMe := myStruct{"1", "guest", "nopassword", []string{"Work", "Documents", "Music"}} - config, err := New(&saveMe) + config, err := quick.New(&saveMe) c.Assert(err, IsNil) c.Assert(config, Not(IsNil)) @@ -103,7 +104,7 @@ func (s *MySuite) TestDiff(c *C) { } mismatch := myNewStruct{"1", "nopassword", []string{"Work", "documents", "Music"}} - newConfig, err := New(&mismatch) + newConfig, err := quick.New(&mismatch) c.Assert(err, IsNil) c.Assert(newConfig, Not(IsNil)) @@ -125,12 +126,12 @@ func (s *MySuite) TestDeepDiff(c *C) { Folders []string } saveMe := myStruct{"1", "guest", "nopassword", []string{"Work", "Documents", "Music"}} - config, err := New(&saveMe) + config, err := quick.New(&saveMe) c.Assert(err, IsNil) c.Assert(config, Not(IsNil)) mismatch := myStruct{"1", "Guest", "nopassword", []string{"Work", "documents", "Music"}} - newConfig, err := New(&mismatch) + newConfig, err := quick.New(&mismatch) c.Assert(err, IsNil) c.Assert(newConfig, Not(IsNil)) diff --git a/session-v1.go b/session-v1.go index d770eb24..17ce3054 100644 --- a/session-v1.go +++ b/session-v1.go @@ -50,12 +50,12 @@ 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.New(errInvalidArgument{}) + return nil, probe.NewError(errInvalidArgument{}) } sessionFile := getSessionFileV1(sid) if _, err := os.Stat(sessionFile); err != nil { - return nil, probe.New(err) + return nil, probe.NewError(err) } s := new(sessionV1) s.Version = "1.0.0" @@ -77,7 +77,7 @@ func loadSessionV1(sid string) (*sessionV1, *probe.Error) { func getSessionIDsV1() (sids []string) { sessionList, err := filepath.Glob(getSessionDir() + "/*") if err != nil { - console.Fatalf("Unable to list session folder ‘%s’, %s", getSessionDir(), probe.New(err)) + console.Fatalf("Unable to list session folder ‘%s’, %s", getSessionDir(), probe.NewError(err)) } for _, path := range sessionList { diff --git a/session-v2.go b/session-v2.go index cdad58a8..e38a00e4 100644 --- a/session-v2.go +++ b/session-v2.go @@ -35,7 +35,7 @@ func migrateSessionV1ToV2() { for _, sid := range getSessionIDsV1() { err := os.Remove(getSessionFileV1(sid)) if err != nil { - console.Fatalf("Migration failed. Unable to remove old session file %s. %s\n", getSessionFileV1(sid), probe.New(err)) + console.Fatalf("Migration failed. Unable to remove old session file %s. %s\n", getSessionFileV1(sid), probe.NewError(err)) } } } @@ -112,7 +112,7 @@ func (s *sessionV2) Save() *probe.Error { defer s.mutex.Unlock() if err := s.DataFP.Sync(); err != nil { - return probe.New(err) + return probe.NewError(err) } qs, err := quick.New(s.Header) @@ -129,7 +129,7 @@ func (s *sessionV2) Close() *probe.Error { defer s.mutex.Unlock() if err := s.DataFP.Close(); err != nil { - return probe.New(err) + return probe.NewError(err) } qs, err := quick.New(s.Header) @@ -148,17 +148,17 @@ func (s *sessionV2) Delete() *probe.Error { if s.DataFP != nil { err := os.Remove(s.DataFP.Name()) if err != nil { - return probe.New(err) + return probe.NewError(err) } } err := os.Remove(getSessionFile(s.SessionID)) if err != nil { - return probe.New(err) + return probe.NewError(err) } if err != nil { - return probe.New(err) + return probe.NewError(err) } return nil @@ -167,12 +167,12 @@ 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.New(errInvalidArgument{}) + return nil, probe.NewError(errInvalidArgument{}) } sessionFile := getSessionFile(sid) if _, err := os.Stat(sessionFile); err != nil { - return nil, probe.New(err) + return nil, probe.NewError(err) } s := &sessionV2{} @@ -209,7 +209,7 @@ 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.New(errUnexpected{})) + console.Fatalf("Empty source URL passed to isCopied() function. %s\n", probe.NewError(errUnexpected{})) } if lastCopied == "" { return false diff --git a/session.go b/session.go index 25134a90..360dd599 100644 --- a/session.go +++ b/session.go @@ -42,7 +42,7 @@ func isSessionDirExists() bool { func createSessionDir() *probe.Error { if err := os.MkdirAll(getSessionDir(), 0700); err != nil { - return probe.New(err) + return probe.NewError(err) } return nil } @@ -78,7 +78,7 @@ func getSessionDataFile(sid string) string { func getSessionIDs() (sids []string) { sessionList, err := filepath.Glob(getSessionDir() + "/*.json") if err != nil { - console.Fatalf("Unable to list session folder ‘%s’, %s", getSessionDir(), probe.New(err)) + console.Fatalf("Unable to list session folder ‘%s’, %s", getSessionDir(), probe.NewError(err)) } for _, path := range sessionList { diff --git a/share-main.go b/share-main.go index 5ef098db..a398c0fa 100644 --- a/share-main.go +++ b/share-main.go @@ -71,7 +71,7 @@ func runShareCmd(ctx *cli.Context) { if len(args) == 2 { var err error expires, err = time.ParseDuration(args.Last()) - Fatal(probe.New(err)) + Fatal(probe.NewError(err)) } targetURL, err := getExpandedURL(url, config.Aliases) Fatal(err) @@ -97,10 +97,10 @@ func doShareCmd(targetURL string, recursive bool, expires time.Duration) *probe. return err.Trace() } if expires.Seconds() < 1 { - return probe.New(errors.New("Too low expires, expiration cannot be less than 1 second")) + return probe.NewError(errors.New("Too low expires, expiration cannot be less than 1 second")) } if expires.Seconds() > 604800 { - return probe.New(errors.New("Too high expires, expiration cannot be larger than 7 days")) + return probe.NewError(errors.New("Too high expires, expiration cannot be larger than 7 days")) } for contentCh := range clnt.List(recursive) { if contentCh.Err != nil { diff --git a/update-main.go b/update-main.go index 027d24d1..ba57a4ef 100644 --- a/update-main.go +++ b/update-main.go @@ -73,7 +73,7 @@ https://dl.minio.io:9000 for continuous updates` var updates Updates decoder := json.NewDecoder(data) if err := decoder.Decode(&updates); err != nil { - return "Unable to parse update fields", probe.New(err) + return "Unable to parse update fields", probe.NewError(err) } latest, _ := time.Parse(http.TimeFormat, updates.BuildDate) if latest.IsZero() { @@ -89,7 +89,7 @@ https://dl.minio.io:9000 for continuous updates` } msg, err := printUpdateNotify(updateString, "new", "old") if err != nil { - return "", probe.New(err) + return "", probe.NewError(err) } console.Println(msg) return "", nil diff --git a/url.go b/url.go index 1abe3ac6..e89cd4b5 100644 --- a/url.go +++ b/url.go @@ -54,7 +54,7 @@ func getExpandedURL(arg string, aliases map[string]string) (urlStr string, err * } if _, err := client.Parse(urlStr); err != nil { // Not a valid URL. Return error - return "", probe.New(errInvalidURL{urlStr}) + return "", probe.NewError(errInvalidURL{urlStr}) } return urlStr, nil }