1
0
mirror of https://github.com/minio/mc.git synced 2025-11-13 12:22:45 +03:00

Probe moves closer to mc, also brings in changes by avoiding it behave like an error interface{}

This commit is contained in:
Harshavardhana
2015-08-07 00:35:55 -07:00
parent 28e8be6f0a
commit 202f9e7646
40 changed files with 204 additions and 216 deletions

5
Godeps/Godeps.json generated
View File

@@ -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"

View File

@@ -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.

View File

@@ -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

View File

@@ -22,7 +22,7 @@ import (
"syscall"
"github.com/minio/cli"
"github.com/minio/minio/pkg/probe"
"github.com/minio/mc/pkg/probe"
)
// Help message.

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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.

View File

@@ -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))
}

View File

@@ -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

View File

@@ -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 {

View File

@@ -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.

View File

@@ -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 {

View File

@@ -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.

View File

@@ -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 {

View File

@@ -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) {

View File

@@ -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.ToError())
}
console.Fatalln(err)
default:
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())
console.Errorln(err.ToError())
return
}
console.Errorln(err)
default:
console.Errorln(err)
}
}

View File

@@ -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 {

View File

@@ -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.

2
ls.go
View File

@@ -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

View File

@@ -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) {

11
main.go
View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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"
)

View File

@@ -21,7 +21,7 @@ import (
"os"
"time"
"github.com/minio/minio/pkg/probe"
"github.com/minio/mc/pkg/probe"
)
// Client - client interface

View File

@@ -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 {

View File

@@ -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))
}

View File

@@ -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

View File

@@ -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))
}

View File

@@ -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 "<nil>"
}
return e.String()
}
// String returns error message.
func (e *Error) String() string {
if e == nil {
if e == nil || e.e == nil {
return "<nil>"
}
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 "<nil>"
}

View File

@@ -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

View File

@@ -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.

View File

@@ -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

View File

@@ -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.

View File

@@ -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() {

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

2
url.go
View File

@@ -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