diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index b559c2ff..fd639a35 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -32,11 +32,6 @@ "Comment": "v0.2.0-21-gd9184e5", "Rev": "d9184e5834efb7cd4a24df4d6ebab9b51dad4d9c" }, - { - "ImportPath": "github.com/minio/minio/pkg/probe", - "Comment": "release-1434511043-300-g28d9565", - "Rev": "28d9565400d68ae1cd79b81075823f10775e6230" - }, { "ImportPath": "github.com/minio/pb", "Rev": "e3e099c334cd89a6fe993f0683eaafd85604290f" diff --git a/access-main.go b/access-main.go index a010a8f3..2b699de6 100644 --- a/access-main.go +++ b/access-main.go @@ -19,7 +19,7 @@ package main import ( "github.com/minio/cli" "github.com/minio/mc/pkg/client" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" ) // Help message. diff --git a/aliases.go b/aliases.go index 4964b93a..4dfcd28c 100644 --- a/aliases.go +++ b/aliases.go @@ -21,7 +21,7 @@ import ( "strings" "github.com/minio/mc/pkg/client" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" ) // validAliasURL: use net/url.Parse to validate diff --git a/cat-main.go b/cat-main.go index 67b36948..aece0f9b 100644 --- a/cat-main.go +++ b/cat-main.go @@ -22,7 +22,7 @@ import ( "syscall" "github.com/minio/cli" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" ) // Help message. diff --git a/cat_test.go b/cat_test.go index 61fd800a..04acf132 100644 --- a/cat_test.go +++ b/cat_test.go @@ -23,6 +23,7 @@ import ( "path/filepath" "github.com/minio/mc/pkg/console" + "github.com/minio/mc/pkg/probe" . "gopkg.in/check.v1" ) @@ -36,10 +37,12 @@ func (s *CmdTestSuite) TestCatCmd(c *C) { objectPathServer := server.URL + "/bucket/object1" data := "hello" dataLen := len(data) - err = putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) - err = putTarget(objectPathServer, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) + + var perr *probe.Error + perr = putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data))) + c.Assert(perr, IsNil) + perr = putTarget(objectPathServer, int64(dataLen), bytes.NewReader([]byte(data))) + c.Assert(perr, IsNil) var sourceURLs []string sourceURLs = append(sourceURLs, objectPath) diff --git a/cmd_test.go b/cmd_test.go index 1a5144b8..fd3deaa8 100644 --- a/cmd_test.go +++ b/cmd_test.go @@ -58,32 +58,32 @@ func (s *CmdTestSuite) SetUpSuite(c *C) { } setMcConfigDir(customConfigDir) - err = createMcConfigDir() - c.Assert(err, IsNil) + perr := createMcConfigDir() + c.Assert(perr, IsNil) - config, err := newConfig() - c.Assert(err, IsNil) + config, perr := newConfig() + c.Assert(perr, IsNil) - err = writeConfig(config) - c.Assert(err, IsNil) + perr = writeConfig(config) + c.Assert(perr, IsNil) - err = createSessionDir() - c.Assert(err, IsNil) + perr = createSessionDir() + c.Assert(perr, IsNil) - _, err = doConfig("invalid", nil) - c.Assert(err, Not(IsNil)) + _, perr = doConfig("invalid", nil) + c.Assert(perr, Not(IsNil)) - _, err = doConfig("alias", []string{"test", "https://test.io"}) - c.Assert(err, IsNil) + _, perr = doConfig("alias", []string{"test", "https://test.io"}) + c.Assert(perr, IsNil) - _, err = doConfig("alias", []string{"test", "https://test.io"}) - c.Assert(err, Not(IsNil)) + _, perr = doConfig("alias", []string{"test", "https://test.io"}) + c.Assert(perr, Not(IsNil)) - _, err = doConfig("alias", []string{"test", "htt://test.io"}) - c.Assert(err, Not(IsNil)) + _, perr = doConfig("alias", []string{"test", "htt://test.io"}) + c.Assert(perr, Not(IsNil)) - _, err = doConfig("alias", []string{"readonly", "https://new.test.io"}) - c.Assert(err, Not(IsNil)) + _, perr = doConfig("alias", []string{"readonly", "https://new.test.io"}) + c.Assert(perr, Not(IsNil)) app = registerApp() objectAPI := objectAPIHandler(objectAPIHandler{lock: &sync.Mutex{}, bucket: "bucket", object: make(map[string][]byte)}) @@ -116,17 +116,17 @@ func (s *CmdTestSuite) TestNewConfigV1(c *C) { c.Assert(err, IsNil) defer os.RemoveAll(root) - conf, err := newConfig() - c.Assert(err, IsNil) + conf, perr := newConfig() + c.Assert(perr, IsNil) configFile := filepath.Join(root, "config.json") - err = conf.Save(configFile) - c.Assert(err, IsNil) + perr = conf.Save(configFile) + c.Assert(perr, IsNil) confNew := newConfigV101() - config, err := quick.New(confNew) - c.Assert(err, IsNil) - err = config.Load(configFile) - c.Assert(err, IsNil) + config, perr := quick.New(confNew) + c.Assert(perr, IsNil) + perr = config.Load(configFile) + c.Assert(perr, IsNil) data := config.Data().(*configV1) type aliases struct { diff --git a/common-methods.go b/common-methods.go index 5b9f265d..03fb06b2 100644 --- a/common-methods.go +++ b/common-methods.go @@ -26,7 +26,7 @@ import ( "github.com/minio/mc/pkg/client" "github.com/minio/mc/pkg/client/fs" "github.com/minio/mc/pkg/client/s3" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" ) // Check if the target URL represents folder. It may or may not exist yet. diff --git a/common_methods_test.go b/common_methods_test.go index 57f0221c..a5be5e3a 100644 --- a/common_methods_test.go +++ b/common_methods_test.go @@ -40,42 +40,42 @@ func (s *CmdTestSuite) TestCommonMethods(c *C) { objectPathServer := server.URL + "/bucket/object1" data := "hello" dataLen := len(data) - err = putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) - err = putTarget(objectPathServer, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) + perr := putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data))) + c.Assert(perr, IsNil) + perr = putTarget(objectPathServer, int64(dataLen), bytes.NewReader([]byte(data))) + c.Assert(perr, IsNil) c.Assert(isTargetURLDir(objectPathServer), Equals, false) c.Assert(isTargetURLDir(server.URL+"/bucket"), Equals, true) - reader, size, err := getSource(objectPathServer) - c.Assert(err, IsNil) + reader, size, perr := getSource(objectPathServer) + c.Assert(perr, IsNil) c.Assert(size, Not(Equals), 0) var results bytes.Buffer _, err = io.CopyN(&results, reader, int64(size)) c.Assert(err, IsNil) c.Assert([]byte(data), DeepEquals, results.Bytes()) - _, content, err := url2Stat(objectPathServer) - c.Assert(err, IsNil) + _, content, perr := url2Stat(objectPathServer) + c.Assert(perr, IsNil) c.Assert(content.Name, Equals, "object1") c.Assert(content.Type.IsRegular(), Equals, true) - _, _, err = getSource(objectPathServer + "invalid") - c.Assert(err, Not(IsNil)) + _, _, perr = getSource(objectPathServer + "invalid") + c.Assert(perr, Not(IsNil)) - _, _, err = url2Stat(objectPath + "invalid") - c.Assert(err, Not(IsNil)) + _, _, perr = url2Stat(objectPath + "invalid") + c.Assert(perr, Not(IsNil)) - _, err = source2Client(objectPathServer) - c.Assert(err, IsNil) + _, perr = source2Client(objectPathServer) + c.Assert(perr, IsNil) - _, err = target2Client(objectPathServer) - c.Assert(err, IsNil) + _, perr = target2Client(objectPathServer) + c.Assert(perr, IsNil) - _, err = source2Client("http://test.minio.io" + "/bucket/fail") - c.Assert(err, Not(IsNil)) + _, perr = source2Client("http://test.minio.io" + "/bucket/fail") + c.Assert(perr, Not(IsNil)) - _, err = target2Client("http://test.minio.io" + "/bucket/fail") - c.Assert(err, Not(IsNil)) + _, perr = target2Client("http://test.minio.io" + "/bucket/fail") + c.Assert(perr, Not(IsNil)) } diff --git a/config-main.go b/config-main.go index d5867c86..597eb8d4 100644 --- a/config-main.go +++ b/config-main.go @@ -21,8 +21,8 @@ import ( "github.com/minio/cli" "github.com/minio/mc/pkg/console" + "github.com/minio/mc/pkg/probe" "github.com/minio/mc/pkg/quick" - "github.com/minio/minio/pkg/probe" ) // Configure minio client diff --git a/config.go b/config.go index 49fb5a0b..c28411c8 100644 --- a/config.go +++ b/config.go @@ -24,8 +24,8 @@ import ( "sync" "github.com/minio/mc/pkg/console" + "github.com/minio/mc/pkg/probe" "github.com/minio/mc/pkg/quick" - "github.com/minio/minio/pkg/probe" ) type configV1 struct { diff --git a/cp-main.go b/cp-main.go index 495ef8f5..8e4fdd72 100644 --- a/cp-main.go +++ b/cp-main.go @@ -28,7 +28,7 @@ import ( "github.com/minio/cli" "github.com/minio/mc/pkg/console" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" ) // Help message. diff --git a/cp-url.go b/cp-url.go index c690e7ce..39025f7e 100644 --- a/cp-url.go +++ b/cp-url.go @@ -23,7 +23,7 @@ import ( "github.com/minio/cli" "github.com/minio/mc/pkg/client" "github.com/minio/mc/pkg/console" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" ) type copyURLs struct { diff --git a/diff-main.go b/diff-main.go index 281a2860..4192aeb0 100644 --- a/diff-main.go +++ b/diff-main.go @@ -19,7 +19,7 @@ package main import ( "github.com/minio/cli" "github.com/minio/mc/pkg/console" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" ) // Help message. diff --git a/diff.go b/diff.go index d15ecebb..690f5b46 100644 --- a/diff.go +++ b/diff.go @@ -24,7 +24,7 @@ import ( "github.com/minio/mc/pkg/client" "github.com/minio/mc/pkg/console" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" "github.com/tchap/go-patricia/patricia" ) @@ -51,7 +51,7 @@ type diffV1 struct { type diff struct { message string - err error + err *probe.Error } func mustURLJoinPath(url1, url2 string) string { diff --git a/diff_test.go b/diff_test.go index e62b8b61..59649311 100644 --- a/diff_test.go +++ b/diff_test.go @@ -24,6 +24,7 @@ import ( "strconv" "github.com/minio/mc/pkg/console" + "github.com/minio/mc/pkg/probe" . "gopkg.in/check.v1" ) @@ -40,14 +41,14 @@ func (s *CmdTestSuite) TestDiffObjects(c *C) { objectPath1 := filepath.Join(root1, "object1") data := "hello" dataLen := len(data) - err = putTarget(objectPath1, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) + perr := putTarget(objectPath1, int64(dataLen), bytes.NewReader([]byte(data))) + c.Assert(perr, IsNil) objectPath2 := filepath.Join(root2, "object1") data = "hello" dataLen = len(data) - err = putTarget(objectPath2, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) + perr = putTarget(objectPath2, int64(dataLen), bytes.NewReader([]byte(data))) + c.Assert(perr, IsNil) for diff := range doDiffCmd(objectPath1, objectPath2, false) { c.Assert(diff.err, IsNil) @@ -65,20 +66,21 @@ func (s *CmdTestSuite) TestDiffDirs(c *C) { c.Assert(err, IsNil) defer os.RemoveAll(root2) + var perr *probe.Error for i := 0; i < 10; i++ { objectPath := filepath.Join(root1, "object"+strconv.Itoa(i)) data := "hello" dataLen := len(data) - err = putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) + perr = putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data))) + c.Assert(perr, IsNil) } for i := 0; i < 10; i++ { objectPath := filepath.Join(root2, "object"+strconv.Itoa(i)) data := "hello" dataLen := len(data) - err = putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) + perr = putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data))) + c.Assert(perr, IsNil) } for diff := range doDiffCmd(root1, root2, false) { diff --git a/error.go b/error.go index b3c5d1bb..76664785 100644 --- a/error.go +++ b/error.go @@ -18,44 +18,28 @@ package main import ( "github.com/minio/mc/pkg/console" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" ) // Fatal wrapper function which takes error and selectively prints stack frames if available on debug -func Fatal(err error) { +func Fatal(err *probe.Error) { if err == nil { return } - switch e := err.(type) { - case *probe.Error: - if e == nil { - return - } - if !globalDebugFlag { - console.Fatalln(e.ToError()) - } - console.Fatalln(err) - default: - console.Fatalln(err) + if !globalDebugFlag { + console.Fatalln(err.ToError()) } + console.Fatalln(err) } // Error synonymous with Fatal but doesn't exit on error != nil -func Error(err error) { +func Error(err *probe.Error) { if err == nil { return } - switch e := err.(type) { - case *probe.Error: - if e == nil { - return - } - if !globalDebugFlag { - console.Errorln(e.ToError()) - return - } - console.Errorln(err) - default: - console.Errorln(err) + if !globalDebugFlag { + console.Errorln(err.ToError()) + return } + console.Errorln(err) } diff --git a/hostconfig.go b/hostconfig.go index 8c4ca670..d8f21dbd 100644 --- a/hostconfig.go +++ b/hostconfig.go @@ -20,7 +20,7 @@ import ( "path/filepath" "github.com/minio/mc/pkg/client" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" ) type hostConfig struct { diff --git a/ls-main.go b/ls-main.go index 34885274..28accd48 100644 --- a/ls-main.go +++ b/ls-main.go @@ -18,7 +18,7 @@ package main import ( "github.com/minio/cli" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" ) // Help message. diff --git a/ls.go b/ls.go index 88bf5a09..e6030b57 100644 --- a/ls.go +++ b/ls.go @@ -25,7 +25,7 @@ import ( "github.com/dustin/go-humanize" "github.com/minio/mc/pkg/client" "github.com/minio/mc/pkg/console" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" ) /// ls - related internal functions diff --git a/ls_test.go b/ls_test.go index 9111b82c..06c09eab 100644 --- a/ls_test.go +++ b/ls_test.go @@ -24,6 +24,7 @@ import ( "strconv" "github.com/minio/mc/pkg/console" + "github.com/minio/mc/pkg/probe" . "gopkg.in/check.v1" ) @@ -33,32 +34,34 @@ func (s *CmdTestSuite) TestLSCmd(c *C) { c.Assert(err, IsNil) defer os.RemoveAll(root) + var perr *probe.Error + for i := 0; i < 10; i++ { objectPath := filepath.Join(root, "object"+strconv.Itoa(i)) data := "hello" dataLen := len(data) - err = putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) + perr = putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data))) + c.Assert(perr, IsNil) } - err = doListCmd(root, false) - c.Assert(err, IsNil) + perr = doListCmd(root, false) + c.Assert(perr, IsNil) - err = doListCmd(root, true) - c.Assert(err, IsNil) + perr = doListCmd(root, true) + c.Assert(perr, IsNil) for i := 0; i < 10; i++ { objectPath := server.URL + "/bucket/object" + strconv.Itoa(i) data := "hello" dataLen := len(data) - err := putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) + perr := putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data))) + c.Assert(perr, IsNil) } - err = doListCmd(server.URL+"/bucket", false) - c.Assert(err, IsNil) + perr = doListCmd(server.URL+"/bucket", false) + c.Assert(perr, IsNil) - err = doListCmd(server.URL+"/bucket", true) - c.Assert(err, IsNil) + perr = doListCmd(server.URL+"/bucket", true) + c.Assert(perr, IsNil) } func (s *CmdTestSuite) TestLSContext(c *C) { diff --git a/main.go b/main.go index 09904c88..08c28bb4 100644 --- a/main.go +++ b/main.go @@ -84,16 +84,13 @@ func registerBefore(ctx *cli.Context) error { if globalDebugFlag { console.NoDebugPrint = false } - switch { - case console.IsValidTheme(themeName) != true: + if console.IsValidTheme(themeName) != true { console.Errorf("Invalid theme, please choose from the following list: %s.\n", console.GetThemeNames()) return errInvalidTheme{Theme: themeName} - default: - err := console.SetTheme(themeName) - if err != nil { - console.Errorf("Failed to set theme ‘%s’.", themeName) - return err - } + } + if err := console.SetTheme(themeName); err != nil { + console.Errorf("Failed to set theme ‘%s’.", themeName) + Error(err) } // Migrate any old version of config / state files to newer format. diff --git a/mb-main.go b/mb-main.go index b9241411..bedd05ae 100644 --- a/mb-main.go +++ b/mb-main.go @@ -19,7 +19,7 @@ package main import ( "github.com/minio/cli" "github.com/minio/mc/pkg/console" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" ) // Help message. diff --git a/mirror-main.go b/mirror-main.go index 73040236..1f9c3419 100644 --- a/mirror-main.go +++ b/mirror-main.go @@ -28,7 +28,7 @@ import ( "github.com/minio/cli" "github.com/minio/mc/pkg/console" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" ) // Help message. diff --git a/mirror-url.go b/mirror-url.go index f1dd621f..48e7e660 100644 --- a/mirror-url.go +++ b/mirror-url.go @@ -24,7 +24,7 @@ import ( "github.com/minio/cli" "github.com/minio/mc/pkg/client" "github.com/minio/mc/pkg/console" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" "github.com/tchap/go-patricia/patricia" ) diff --git a/pkg/client/client.go b/pkg/client/client.go index 19927c7e..cd55bdc3 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -21,7 +21,7 @@ import ( "os" "time" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" ) // Client - client interface diff --git a/pkg/client/fs/fs.go b/pkg/client/fs/fs.go index 2662e63b..ab7726fc 100644 --- a/pkg/client/fs/fs.go +++ b/pkg/client/fs/fs.go @@ -26,7 +26,7 @@ import ( "io/ioutil" "github.com/minio/mc/pkg/client" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" ) type fsClient struct { diff --git a/pkg/client/fs/fs_test.go b/pkg/client/fs/fs_test.go index 5d71a219..b10f4a8b 100644 --- a/pkg/client/fs/fs_test.go +++ b/pkg/client/fs/fs_test.go @@ -40,30 +40,34 @@ func (s *MySuite) TestList(c *C) { defer os.RemoveAll(root) objectPath := filepath.Join(root, "object1") - fsc, err := New(objectPath) + fsc, perr := New(objectPath) c.Assert(err, IsNil) data := "hello" dataLen := len(data) - err = fsc.PutObject(int64(dataLen), bytes.NewReader([]byte(data))) + perr = fsc.PutObject(int64(dataLen), bytes.NewReader([]byte(data))) c.Assert(err, IsNil) objectPath = filepath.Join(root, "object2") - fsc, err = New(objectPath) + fsc, perr = New(objectPath) c.Assert(err, IsNil) - err = fsc.PutObject(int64(dataLen), bytes.NewReader([]byte(data))) + perr = fsc.PutObject(int64(dataLen), bytes.NewReader([]byte(data))) c.Assert(err, IsNil) - fsc, err = New(root) + fsc, perr = New(root) c.Assert(err, IsNil) var contents []*client.Content for contentCh := range fsc.List(false) { + if contentCh.Err != nil { + perr = contentCh.Err + break + } contents = append(contents, contentCh.Content) } - c.Assert(err, IsNil) + c.Assert(perr, IsNil) c.Assert(len(contents), Equals, 2) for _, content := range contents { @@ -71,20 +75,24 @@ func (s *MySuite) TestList(c *C) { } objectPath = filepath.Join(root, "test1/newObject1") - fsc, err = New(objectPath) + fsc, perr = New(objectPath) c.Assert(err, IsNil) - err = fsc.PutObject(int64(dataLen), bytes.NewReader([]byte(data))) + perr = fsc.PutObject(int64(dataLen), bytes.NewReader([]byte(data))) c.Assert(err, IsNil) - fsc, err = New(root) + fsc, perr = New(root) c.Assert(err, IsNil) contents = nil for contentCh := range fsc.List(false) { + if contentCh.Err != nil { + perr = contentCh.Err + break + } contents = append(contents, contentCh.Content) } - c.Assert(err, IsNil) + c.Assert(perr, IsNil) c.Assert(len(contents), Equals, 3) for _, content := range contents { @@ -95,11 +103,15 @@ func (s *MySuite) TestList(c *C) { c.Assert(content.Type.IsDir(), Equals, true) } - fsc, err = New(root) + fsc, perr = New(root) c.Assert(err, IsNil) contents = nil for contentCh := range fsc.List(true) { + if contentCh.Err != nil { + perr = contentCh.Err + break + } contents = append(contents, contentCh.Content) } @@ -127,10 +139,10 @@ func (s *MySuite) TestPutBucket(c *C) { defer os.RemoveAll(root) bucketPath := filepath.Join(root, "bucket") - fsc, err := New(bucketPath) - c.Assert(err, IsNil) - err = fsc.MakeBucket() - c.Assert(err, IsNil) + fsc, perr := New(bucketPath) + c.Assert(perr, IsNil) + perr = fsc.MakeBucket() + c.Assert(perr, IsNil) } func (s *MySuite) TestStatBucket(c *C) { @@ -140,12 +152,12 @@ func (s *MySuite) TestStatBucket(c *C) { bucketPath := filepath.Join(root, "bucket") - fsc, err := New(bucketPath) - c.Assert(err, IsNil) - err = fsc.MakeBucket() - c.Assert(err, IsNil) - _, err = fsc.Stat() - c.Assert(err, IsNil) + fsc, perr := New(bucketPath) + c.Assert(perr, IsNil) + perr = fsc.MakeBucket() + c.Assert(perr, IsNil) + _, perr = fsc.Stat() + c.Assert(perr, IsNil) } func (s *MySuite) TestPutBucketACL(c *C) { @@ -154,13 +166,13 @@ func (s *MySuite) TestPutBucketACL(c *C) { defer os.RemoveAll(root) bucketPath := filepath.Join(root, "bucket") - fsc, err := New(bucketPath) - c.Assert(err, IsNil) - err = fsc.MakeBucket() - c.Assert(err, IsNil) + fsc, perr := New(bucketPath) + c.Assert(perr, IsNil) + perr = fsc.MakeBucket() + c.Assert(perr, IsNil) - err = fsc.SetBucketACL("private") - c.Assert(err, IsNil) + perr = fsc.SetBucketACL("private") + c.Assert(perr, IsNil) } func (s *MySuite) TestPutObject(c *C) { @@ -169,14 +181,14 @@ func (s *MySuite) TestPutObject(c *C) { defer os.RemoveAll(root) objectPath := filepath.Join(root, "object") - fsc, err := New(objectPath) - c.Assert(err, IsNil) + fsc, perr := New(objectPath) + c.Assert(perr, IsNil) data := "hello" dataLen := len(data) - err = fsc.PutObject(int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) + perr = fsc.PutObject(int64(dataLen), bytes.NewReader([]byte(data))) + c.Assert(perr, IsNil) } func (s *MySuite) TestGetObject(c *C) { @@ -185,17 +197,17 @@ func (s *MySuite) TestGetObject(c *C) { defer os.RemoveAll(root) objectPath := filepath.Join(root, "object") - fsc, err := New(objectPath) - c.Assert(err, IsNil) + fsc, perr := New(objectPath) + c.Assert(perr, IsNil) data := "hello" dataLen := len(data) - err = fsc.PutObject(int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) + perr = fsc.PutObject(int64(dataLen), bytes.NewReader([]byte(data))) + c.Assert(perr, IsNil) - reader, size, err := fsc.GetObject(0, 0) - c.Assert(err, IsNil) + reader, size, perr := fsc.GetObject(0, 0) + c.Assert(perr, IsNil) var results bytes.Buffer _, err = io.CopyN(&results, reader, int64(size)) c.Assert(err, IsNil) @@ -209,17 +221,17 @@ func (s *MySuite) TestGetObjectRange(c *C) { defer os.RemoveAll(root) objectPath := filepath.Join(root, "object") - fsc, err := New(objectPath) - c.Assert(err, IsNil) + fsc, perr := New(objectPath) + c.Assert(perr, IsNil) data := "hello world" dataLen := len(data) - err = fsc.PutObject(int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) + perr = fsc.PutObject(int64(dataLen), bytes.NewReader([]byte(data))) + c.Assert(perr, IsNil) - reader, size, err := fsc.GetObject(0, 5) - c.Assert(err, IsNil) + reader, size, perr := fsc.GetObject(0, 5) + c.Assert(perr, IsNil) var results bytes.Buffer _, err = io.CopyN(&results, reader, int64(size)) c.Assert(err, IsNil) @@ -232,17 +244,17 @@ func (s *MySuite) TestStatObject(c *C) { defer os.RemoveAll(root) objectPath := filepath.Join(root, "object") - fsc, err := New(objectPath) - c.Assert(err, IsNil) + fsc, perr := New(objectPath) + c.Assert(perr, IsNil) data := "hello" dataLen := len(data) - err = fsc.PutObject(int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) + perr = fsc.PutObject(int64(dataLen), bytes.NewReader([]byte(data))) + c.Assert(perr, IsNil) - content, err := fsc.Stat() - c.Assert(err, IsNil) + content, perr := fsc.Stat() + c.Assert(perr, IsNil) c.Assert(content.Name, Equals, objectPath) c.Assert(content.Size, Equals, int64(dataLen)) } diff --git a/pkg/client/s3/s3.go b/pkg/client/s3/s3.go index 84d7fd71..383489fe 100644 --- a/pkg/client/s3/s3.go +++ b/pkg/client/s3/s3.go @@ -25,8 +25,8 @@ import ( "time" "github.com/minio/mc/pkg/client" + "github.com/minio/mc/pkg/probe" "github.com/minio/minio-go" - "github.com/minio/minio/pkg/probe" ) // Config - see http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RESTAuthentication.html @@ -178,7 +178,7 @@ func (c *s3Client) Stat() (*client.Content, *probe.Error) { if errResponse.Code == "NoSuchKey" { for content := range c.List(false) { if content.Err != nil { - return nil, probe.New(content.Err) + return nil, content.Err.Trace() } content.Content.Type = os.ModeDir content.Content.Name = object diff --git a/pkg/console/console.go b/pkg/console/console.go index 2b2cc3a8..468c1b1f 100644 --- a/pkg/console/console.go +++ b/pkg/console/console.go @@ -25,7 +25,7 @@ import ( "github.com/fatih/color" "github.com/mattn/go-isatty" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" "github.com/shiena/ansicolor" ) @@ -352,7 +352,7 @@ func Unlock() { } // SetTheme sets a color theme -func SetTheme(themeName string) error { +func SetTheme(themeName string) *probe.Error { if !IsValidTheme(themeName) { return probe.New(fmt.Errorf("Unsupported theme name [%s]", themeName)) } diff --git a/Godeps/_workspace/src/github.com/minio/minio/pkg/probe/probe.go b/pkg/probe/probe.go similarity index 97% rename from Godeps/_workspace/src/github.com/minio/minio/pkg/probe/probe.go rename to pkg/probe/probe.go index 957c3384..ffab300f 100644 --- a/Godeps/_workspace/src/github.com/minio/minio/pkg/probe/probe.go +++ b/pkg/probe/probe.go @@ -124,17 +124,9 @@ func (e *Error) Untrace() { e.tracePoints = e.tracePoints[:l-1] } -// Error returns error string. -func (e *Error) Error() string { - if e == nil { - return "" - } - return e.String() -} - // String returns error message. func (e *Error) String() string { - if e == nil { + if e == nil || e.e == nil { return "" } e.lock.RLock() @@ -164,7 +156,7 @@ func (e *Error) String() string { // JSON returns JSON formated error trace. func (e *Error) JSON() string { - if e == nil { + if e == nil || e.e == nil { return "" } diff --git a/Godeps/_workspace/src/github.com/minio/minio/pkg/probe/probe_test.go b/pkg/probe/probe_test.go similarity index 100% rename from Godeps/_workspace/src/github.com/minio/minio/pkg/probe/probe_test.go rename to pkg/probe/probe_test.go diff --git a/pkg/quick/quick.go b/pkg/quick/quick.go index f10220a9..08ef2415 100644 --- a/pkg/quick/quick.go +++ b/pkg/quick/quick.go @@ -29,7 +29,7 @@ import ( "sync" "github.com/fatih/structs" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" ) // Config - generic config interface functions diff --git a/session-main.go b/session-main.go index 0d0eaf7b..bba62f6c 100644 --- a/session-main.go +++ b/session-main.go @@ -23,7 +23,7 @@ import ( "github.com/minio/cli" "github.com/minio/mc/pkg/console" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" ) // Help message. diff --git a/session-v1.go b/session-v1.go index 59d51f74..d770eb24 100644 --- a/session-v1.go +++ b/session-v1.go @@ -25,8 +25,8 @@ import ( "time" "github.com/minio/mc/pkg/console" + "github.com/minio/mc/pkg/probe" "github.com/minio/mc/pkg/quick" - "github.com/minio/minio/pkg/probe" ) type sessionV1 struct { @@ -48,7 +48,7 @@ func (s sessionV1) String() string { } // loadSession - reads session file if exists and re-initiates internal variables -func loadSessionV1(sid string) (*sessionV1, error) { +func loadSessionV1(sid string) (*sessionV1, *probe.Error) { if !isSessionDirExists() { return nil, probe.New(errInvalidArgument{}) } @@ -86,7 +86,7 @@ func getSessionIDsV1() (sids []string) { if sidReg.Match([]byte(sid)) { sessionV1, err := loadSessionV1(sid) if err != nil { - console.Fatalf("Unable to load session ‘%s’, %s", sid, probe.New(err)) + console.Fatalf("Unable to load session ‘%s’, %s", sid, err.Trace()) } if sessionV1.Version != "1.0.0" { continue diff --git a/session-v2.go b/session-v2.go index f31f3312..cdad58a8 100644 --- a/session-v2.go +++ b/session-v2.go @@ -25,8 +25,8 @@ import ( "time" "github.com/minio/mc/pkg/console" + "github.com/minio/mc/pkg/probe" "github.com/minio/mc/pkg/quick" - "github.com/minio/minio/pkg/probe" ) // migrateSessionV1ToV2 migrates all session files from v1 to v2. diff --git a/session.go b/session.go index f8d7e54a..25134a90 100644 --- a/session.go +++ b/session.go @@ -24,7 +24,7 @@ import ( "time" "github.com/minio/mc/pkg/console" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" ) func migrateSession() { diff --git a/session_test.go b/session_test.go index 3dbe0af3..396a0cfc 100644 --- a/session_test.go +++ b/session_test.go @@ -32,26 +32,26 @@ func (s *CmdTestSuite) TestValidSessionID(c *C) { } func (s *CmdTestSuite) TestSession(c *C) { - err := createSessionDir() - c.Assert(err, IsNil) + perr := createSessionDir() + c.Assert(perr, IsNil) c.Assert(isSessionDirExists(), Equals, true) session := newSessionV2() c.Assert(session.Header.CommandArgs, IsNil) c.Assert(len(session.SessionID), Equals, 8) - err = session.Close() - c.Assert(err, IsNil) + perr = session.Close() + c.Assert(perr, IsNil) - savedSession, err := loadSessionV2(session.SessionID) - c.Assert(err, IsNil) + savedSession, perr := loadSessionV2(session.SessionID) + c.Assert(perr, IsNil) c.Assert(session.SessionID, Equals, savedSession.SessionID) - err = savedSession.Close() - c.Assert(err, IsNil) + perr = savedSession.Close() + c.Assert(perr, IsNil) - err = savedSession.Delete() - c.Assert(err, IsNil) + perr = savedSession.Delete() + c.Assert(perr, IsNil) } func (s *CmdTestSuite) TestSessionContext(c *C) { @@ -72,16 +72,16 @@ func (s *CmdTestSuite) TestSessionContext(c *C) { c.Assert(console.IsExited, Equals, true) console.IsExited = false - err = createSessionDir() - c.Assert(err, IsNil) + perr := createSessionDir() + c.Assert(perr, IsNil) c.Assert(isSessionDirExists(), Equals, true) session := newSessionV2() c.Assert(session.Header.CommandArgs, IsNil) c.Assert(len(session.SessionID), Equals, 8) - err = session.Save() - c.Assert(err, IsNil) + perr = session.Save() + c.Assert(perr, IsNil) err = app.Run([]string{os.Args[0], "session", "clear", session.SessionID}) c.Assert(err, IsNil) diff --git a/share-main.go b/share-main.go index ec0c44fc..8aa427eb 100644 --- a/share-main.go +++ b/share-main.go @@ -25,7 +25,7 @@ import ( "github.com/minio/cli" "github.com/minio/mc/pkg/client" "github.com/minio/mc/pkg/console" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" ) // Help message. @@ -70,7 +70,7 @@ func runShareCmd(ctx *cli.Context) { if len(args) == 2 { var err error expires, err = time.ParseDuration(args.Last()) - Fatal(err) + Fatal(probe.New(err)) } targetURL, err := getExpandedURL(url, config.Aliases) Fatal(err) diff --git a/update-main.go b/update-main.go index 3cf0908d..027d24d1 100644 --- a/update-main.go +++ b/update-main.go @@ -24,7 +24,7 @@ import ( "github.com/minio/cli" "github.com/minio/mc/pkg/console" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" ) // Updates container to hold updates json diff --git a/url.go b/url.go index 8ea5759f..1abe3ac6 100644 --- a/url.go +++ b/url.go @@ -20,7 +20,7 @@ import ( "strings" "github.com/minio/mc/pkg/client" - "github.com/minio/minio/pkg/probe" + "github.com/minio/mc/pkg/probe" ) // ``...`` recursiveSeparator