Merge pull request #889 from harshavardhana/pr_out_add_mc_top_level_error_handling_without_printing_stack_traces
This commit is contained in:
+2
-3
@@ -21,7 +21,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/minio/mc/pkg/client"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
// validAliasURL: use net/url.Parse to validate
|
||||
@@ -49,7 +48,7 @@ func isValidAliasName(aliasName string) bool {
|
||||
func aliasExpand(aliasedURL string, aliases map[string]string) (newURL string, err error) {
|
||||
u, err := client.Parse(aliasedURL)
|
||||
if err != nil {
|
||||
return aliasedURL, iodine.New(errInvalidURL{URL: aliasedURL}, nil)
|
||||
return aliasedURL, NewIodine(errInvalidURL{URL: aliasedURL}, nil)
|
||||
}
|
||||
// proper URL
|
||||
if u.Host != "" {
|
||||
@@ -69,7 +68,7 @@ func aliasExpand(aliasedURL string, aliases map[string]string) (newURL string, e
|
||||
trimmedURL := expandedURL + "/" + strings.TrimPrefix(strings.TrimPrefix(splits[1], "/"), "\\")
|
||||
u, err := client.Parse(trimmedURL)
|
||||
if err != nil {
|
||||
return aliasedURL, iodine.New(errInvalidURL{URL: aliasedURL}, nil)
|
||||
return aliasedURL, NewIodine(errInvalidURL{URL: aliasedURL}, nil)
|
||||
}
|
||||
return u.String(), nil
|
||||
}
|
||||
|
||||
+3
-4
@@ -22,7 +22,6 @@ import (
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/client"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
// Help message.
|
||||
@@ -75,7 +74,7 @@ func runAccessCmd(ctx *cli.Context) {
|
||||
for _, arg := range ctx.Args().Tail() {
|
||||
targetURL, err := getExpandedURL(arg, config.Aliases)
|
||||
if err != nil {
|
||||
switch e := iodine.ToError(err).(type) {
|
||||
switch e := ToError(err).(type) {
|
||||
case errUnsupportedScheme:
|
||||
console.Fatalf("Unknown type of URL %s. %s\n", e.url, err)
|
||||
default:
|
||||
@@ -96,7 +95,7 @@ func doUpdateAccessCmd(targetURL string, targetACL bucketACL) (string, error) {
|
||||
clnt, err = target2Client(targetURL)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Unable to initialize client for ‘%s’", targetURL)
|
||||
return msg, iodine.New(err, nil)
|
||||
return msg, NewIodine(err, nil)
|
||||
}
|
||||
return doUpdateAccess(clnt, targetACL)
|
||||
}
|
||||
@@ -105,7 +104,7 @@ func doUpdateAccess(clnt client.Client, targetACL bucketACL) (string, error) {
|
||||
err := clnt.SetBucketACL(targetACL.String())
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Failed to add bucket access policy for URL ‘%s’", clnt.URL().String())
|
||||
return msg, iodine.New(err, nil)
|
||||
return msg, NewIodine(err, nil)
|
||||
}
|
||||
return "Bucket access policy updated successfully : " + clnt.URL().String(), nil
|
||||
}
|
||||
|
||||
+6
-7
@@ -23,7 +23,6 @@ import (
|
||||
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
// Help message.
|
||||
@@ -72,7 +71,7 @@ func runCatCmd(ctx *cli.Context) {
|
||||
for _, arg := range ctx.Args() {
|
||||
sourceURL, err := getExpandedURL(arg, config.Aliases)
|
||||
if err != nil {
|
||||
switch e := iodine.ToError(err).(type) {
|
||||
switch e := ToError(err).(type) {
|
||||
case errUnsupportedScheme:
|
||||
console.Fatalf("Unknown type of URL %s. %s\n", e.url, err)
|
||||
default:
|
||||
@@ -89,24 +88,24 @@ func runCatCmd(ctx *cli.Context) {
|
||||
func doCatCmd(sourceURL string) (string, error) {
|
||||
sourceClnt, err := source2Client(sourceURL)
|
||||
if err != nil {
|
||||
return "Unable to create client: " + sourceURL, iodine.New(err, nil)
|
||||
return "Unable to create client: " + sourceURL, NewIodine(err, nil)
|
||||
}
|
||||
reader, size, err := sourceClnt.GetObject(0, 0)
|
||||
if err != nil {
|
||||
return "Unable to retrieve file: " + sourceURL, iodine.New(err, nil)
|
||||
return "Unable to retrieve file: " + sourceURL, NewIodine(err, nil)
|
||||
}
|
||||
defer reader.Close()
|
||||
_, err = io.CopyN(os.Stdout, reader, int64(size))
|
||||
if err != nil {
|
||||
switch e := iodine.ToError(err).(type) {
|
||||
switch e := ToError(err).(type) {
|
||||
case *os.PathError:
|
||||
if e.Err == syscall.EPIPE {
|
||||
// stdout closed by the user. Gracefully exit.
|
||||
return "", nil
|
||||
}
|
||||
return "Writing data to stdout failed, unexpected problem.. please report this error", iodine.New(err, nil)
|
||||
return "Writing data to stdout failed, unexpected problem.. please report this error", NewIodine(err, nil)
|
||||
default:
|
||||
return "Reading data from source failed: " + sourceURL, iodine.New(err, nil)
|
||||
return "Reading data from source failed: " + sourceURL, NewIodine(err, nil)
|
||||
}
|
||||
}
|
||||
return "", nil
|
||||
|
||||
+21
-22
@@ -22,7 +22,6 @@ import (
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/quick"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
// Configure minio client
|
||||
@@ -79,25 +78,25 @@ func saveConfig(arg string, aliases []string) error {
|
||||
switch arg {
|
||||
case "generate":
|
||||
if isMcConfigExists() {
|
||||
return iodine.New(errConfigExists{}, nil)
|
||||
return NewIodine(errConfigExists{}, nil)
|
||||
}
|
||||
config, err := newConfig()
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
return NewIodine(err, nil)
|
||||
}
|
||||
err = writeConfig(config)
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
return NewIodine(err, nil)
|
||||
}
|
||||
return nil
|
||||
case "alias":
|
||||
config, err := addAlias(aliases)
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
return NewIodine(err, nil)
|
||||
}
|
||||
return writeConfig(config)
|
||||
default:
|
||||
return iodine.New(errInvalidArgument{}, nil)
|
||||
return NewIodine(errInvalidArgument{}, nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,24 +104,24 @@ func saveConfig(arg string, aliases []string) error {
|
||||
func doConfig(arg string, aliases []string) (string, error) {
|
||||
configPath, err := getMcConfigPath()
|
||||
if err != nil {
|
||||
return "Unable to determine config file path.", iodine.New(err, nil)
|
||||
return "Unable to determine config file path.", NewIodine(err, nil)
|
||||
}
|
||||
err = saveConfig(arg, aliases)
|
||||
if err != nil {
|
||||
switch iodine.ToError(err).(type) {
|
||||
switch ToError(err).(type) {
|
||||
case errConfigExists:
|
||||
return "Configuration file [" + configPath + "]", iodine.New(err, nil)
|
||||
return "Configuration file [" + configPath + "]", NewIodine(err, nil)
|
||||
case errInvalidArgument:
|
||||
return "Incorrect usage, please use \"mc config help\" ", iodine.New(err, nil)
|
||||
return "Incorrect usage, please use \"mc config help\" ", NewIodine(err, nil)
|
||||
case errAliasExists:
|
||||
return "Alias name: [" + aliases[0] + "]", iodine.New(err, nil)
|
||||
return "Alias name: [" + aliases[0] + "]", NewIodine(err, nil)
|
||||
case errInvalidAliasName:
|
||||
return "Alias [" + aliases[0] + "] is reserved word or invalid", iodine.New(err, nil)
|
||||
return "Alias [" + aliases[0] + "] is a reserved word or invalid name", NewIodine(err, nil)
|
||||
case errInvalidURL:
|
||||
return "Alias [" + aliases[1] + "] is invalid URL", iodine.New(err, nil)
|
||||
return "[" + aliases[1] + "] is invalid URL doesn't start with http or https", NewIodine(err, nil)
|
||||
default:
|
||||
// unexpected error
|
||||
return "Unable to generate config file [" + configPath + "].", iodine.New(err, nil)
|
||||
return "Unable to generate config file [" + configPath + "].", NewIodine(err, nil)
|
||||
}
|
||||
}
|
||||
if arg == "alias" {
|
||||
@@ -131,41 +130,41 @@ func doConfig(arg string, aliases []string) (string, error) {
|
||||
if arg == "generate" {
|
||||
return "Configuration written to [" + configPath + "]. Please update your access credentials.", nil
|
||||
}
|
||||
return "", iodine.New(errUnexpected{}, nil)
|
||||
return "", NewIodine(errUnexpected{}, nil)
|
||||
}
|
||||
|
||||
// addAlias - add new aliases
|
||||
func addAlias(aliases []string) (quick.Config, error) {
|
||||
if len(aliases) < 2 {
|
||||
return nil, iodine.New(errInvalidArgument{}, nil)
|
||||
return nil, NewIodine(errInvalidArgument{}, nil)
|
||||
}
|
||||
conf := newConfigV1()
|
||||
config, err := quick.New(conf)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
return nil, NewIodine(err, nil)
|
||||
}
|
||||
config.Load(mustGetMcConfigPath())
|
||||
|
||||
aliasName := aliases[0]
|
||||
url := strings.TrimSuffix(aliases[1], "/")
|
||||
if strings.HasPrefix(aliasName, "http") {
|
||||
return nil, iodine.New(errInvalidAliasName{name: aliasName}, nil)
|
||||
return nil, NewIodine(errInvalidAliasName{name: aliasName}, nil)
|
||||
}
|
||||
if !strings.HasPrefix(url, "http") {
|
||||
return nil, iodine.New(errInvalidURL{URL: url}, nil)
|
||||
return nil, NewIodine(errInvalidURL{URL: url}, nil)
|
||||
}
|
||||
if !isValidAliasName(aliasName) {
|
||||
return nil, iodine.New(errInvalidAliasName{name: aliasName}, nil)
|
||||
return nil, NewIodine(errInvalidAliasName{name: aliasName}, nil)
|
||||
}
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV1)
|
||||
if _, ok := newConf.Aliases[aliasName]; ok {
|
||||
return nil, iodine.New(errAliasExists{}, nil)
|
||||
return nil, NewIodine(errAliasExists{}, nil)
|
||||
}
|
||||
newConf.Aliases[aliasName] = url
|
||||
newConfig, err := quick.New(newConf)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
return nil, NewIodine(err, nil)
|
||||
}
|
||||
return newConfig, nil
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import (
|
||||
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
// Help message.
|
||||
@@ -85,7 +84,7 @@ func doCopy(cpURLs copyURLs, bar *barSend, cpQueue chan bool, wg *sync.WaitGroup
|
||||
if !globalQuietFlag || !globalJSONFlag {
|
||||
bar.ErrorGet(length)
|
||||
}
|
||||
return iodine.New(err, map[string]string{"URL": cpURLs.SourceContent.Name})
|
||||
return NewIodine(err, map[string]string{"URL": cpURLs.SourceContent.Name})
|
||||
}
|
||||
|
||||
var newReader io.ReadCloser
|
||||
@@ -107,7 +106,7 @@ func doCopy(cpURLs copyURLs, bar *barSend, cpQueue chan bool, wg *sync.WaitGroup
|
||||
if !globalQuietFlag || !globalJSONFlag {
|
||||
bar.ErrorPut(length)
|
||||
}
|
||||
console.Errorln(iodine.ToError(err))
|
||||
console.Errorln(ToError(err))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
+5
-6
@@ -19,7 +19,6 @@ package main
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
// Help message.
|
||||
@@ -67,7 +66,7 @@ func runDiffCmd(ctx *cli.Context) {
|
||||
var err error
|
||||
firstURL, err = getExpandedURL(firstURL, config.Aliases)
|
||||
if err != nil {
|
||||
switch e := iodine.ToError(err).(type) {
|
||||
switch e := ToError(err).(type) {
|
||||
case errUnsupportedScheme:
|
||||
console.Fatalf("Unknown type of URL %s. %s\n", e.url, err)
|
||||
default:
|
||||
@@ -76,7 +75,7 @@ func runDiffCmd(ctx *cli.Context) {
|
||||
}
|
||||
secondURL, err = getExpandedURL(secondURL, config.Aliases)
|
||||
if err != nil {
|
||||
switch e := iodine.ToError(err).(type) {
|
||||
switch e := ToError(err).(type) {
|
||||
case errUnsupportedScheme:
|
||||
console.Fatalf("Unknown type of URL %s. %s\n", e.url, err)
|
||||
default:
|
||||
@@ -101,7 +100,7 @@ func doDiffInRoutine(firstURL, secondURL string, recursive bool, ch chan diff) {
|
||||
if err != nil {
|
||||
ch <- diff{
|
||||
message: "Failed to stat ‘" + firstURL + "’",
|
||||
err: iodine.New(err, nil),
|
||||
err: NewIodine(err, nil),
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -109,7 +108,7 @@ func doDiffInRoutine(firstURL, secondURL string, recursive bool, ch chan diff) {
|
||||
if err != nil {
|
||||
ch <- diff{
|
||||
message: "Failed to stat ‘" + secondURL + "’",
|
||||
err: iodine.New(err, nil),
|
||||
err: NewIodine(err, nil),
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -120,7 +119,7 @@ func doDiffInRoutine(firstURL, secondURL string, recursive bool, ch chan diff) {
|
||||
if err != nil {
|
||||
ch <- diff{
|
||||
message: "Unable to construct new URL from ‘" + secondURL + "’ using ‘" + firstURL,
|
||||
err: iodine.New(err, nil),
|
||||
err: NewIodine(err, nil),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package main
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
// Help message.
|
||||
@@ -88,7 +87,7 @@ func runListCmd(ctx *cli.Context) {
|
||||
for _, arg := range args {
|
||||
targetURL, err := getExpandedURL(arg, config.Aliases)
|
||||
if err != nil {
|
||||
switch e := iodine.ToError(err).(type) {
|
||||
switch e := ToError(err).(type) {
|
||||
case errUnsupportedScheme:
|
||||
console.Fatalf("Unknown type of URL %s. %s\n", e.url, err)
|
||||
default:
|
||||
@@ -108,11 +107,11 @@ func runListCmd(ctx *cli.Context) {
|
||||
func doListCmd(targetURL string, recursive bool) error {
|
||||
clnt, err := target2Client(targetURL)
|
||||
if err != nil {
|
||||
return iodine.New(err, map[string]string{"Target": targetURL})
|
||||
return NewIodine(err, map[string]string{"Target": targetURL})
|
||||
}
|
||||
err = doList(clnt, recursive)
|
||||
if err != nil {
|
||||
return iodine.New(err, map[string]string{"Target": targetURL})
|
||||
return NewIodine(err, map[string]string{"Target": targetURL})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/client"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
// Help message.
|
||||
@@ -67,7 +66,7 @@ func runMakeBucketCmd(ctx *cli.Context) {
|
||||
for _, arg := range ctx.Args() {
|
||||
targetURL, err := getExpandedURL(arg, config.Aliases)
|
||||
if err != nil {
|
||||
switch e := iodine.ToError(err).(type) {
|
||||
switch e := ToError(err).(type) {
|
||||
case errUnsupportedScheme:
|
||||
console.Fatalf("Unknown type of URL %s. %s\n", e.url, err)
|
||||
default:
|
||||
@@ -89,7 +88,7 @@ func doMakeBucketCmd(targetURL string) (string, error) {
|
||||
clnt, err = target2Client(targetURL)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Unable to initialize client for ‘%s’", targetURL)
|
||||
return msg, iodine.New(err, nil)
|
||||
return msg, NewIodine(err, nil)
|
||||
}
|
||||
return doMakeBucket(clnt)
|
||||
}
|
||||
@@ -99,7 +98,7 @@ func doMakeBucket(clnt client.Client) (string, error) {
|
||||
err := clnt.MakeBucket()
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Failed to create bucket for URL ‘%s’", clnt.URL().String())
|
||||
return msg, iodine.New(err, nil)
|
||||
return msg, NewIodine(err, nil)
|
||||
}
|
||||
return "Bucket created successfully : " + clnt.URL().String(), nil
|
||||
}
|
||||
|
||||
+3
-4
@@ -22,7 +22,6 @@ import (
|
||||
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
// Help message.
|
||||
@@ -60,7 +59,7 @@ func listSessions() error {
|
||||
for _, sid := range getSessionIDs() {
|
||||
s, err := loadSessionV2(sid)
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
return NewIodine(err, nil)
|
||||
}
|
||||
console.Prints(s)
|
||||
}
|
||||
@@ -72,7 +71,7 @@ func clearSession(sid string) {
|
||||
for _, sid := range getSessionIDs() {
|
||||
session, err := loadSessionV2(sid)
|
||||
if err != nil {
|
||||
console.Fatalf("Unable to load session ‘%s’, %s", sid, iodine.New(err, nil))
|
||||
console.Fatalf("Unable to load session ‘%s’, %s", sid, NewIodine(err, nil))
|
||||
}
|
||||
session.Close()
|
||||
}
|
||||
@@ -85,7 +84,7 @@ func clearSession(sid string) {
|
||||
|
||||
session, err := loadSessionV2(sid)
|
||||
if err != nil {
|
||||
console.Fatalf("Unable to load session ‘%s’, %s", sid, iodine.New(err, nil))
|
||||
console.Fatalf("Unable to load session ‘%s’, %s", sid, NewIodine(err, nil))
|
||||
}
|
||||
session.Close()
|
||||
}
|
||||
|
||||
+3
-4
@@ -24,7 +24,6 @@ import (
|
||||
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
// Updates container to hold updates json
|
||||
@@ -58,11 +57,11 @@ EXAMPLES:
|
||||
func doUpdateCheck() (string, error) {
|
||||
clnt, err := url2Client(mcUpdateURL)
|
||||
if err != nil {
|
||||
return "Unable to create client: " + mcUpdateURL, iodine.New(err, map[string]string{"failedURL": mcUpdateURL})
|
||||
return "Unable to create client: " + mcUpdateURL, NewIodine(err, map[string]string{"failedURL": mcUpdateURL})
|
||||
}
|
||||
data, _, err := clnt.GetObject(0, 0)
|
||||
if err != nil {
|
||||
return "Unable to read: " + mcUpdateURL, iodine.New(err, map[string]string{"failedURL": mcUpdateURL})
|
||||
return "Unable to read: " + mcUpdateURL, NewIodine(err, map[string]string{"failedURL": mcUpdateURL})
|
||||
}
|
||||
current, _ := time.Parse(time.RFC3339Nano, Version)
|
||||
if current.IsZero() {
|
||||
@@ -74,7 +73,7 @@ https://dl.minio.io:9000 for continuous updates`
|
||||
decoder := json.NewDecoder(data)
|
||||
err = decoder.Decode(&updates)
|
||||
if err != nil {
|
||||
return "Unable to parse update fields", iodine.New(err, map[string]string{"failedURL": mcUpdateURL})
|
||||
return "Unable to parse update fields", NewIodine(err, map[string]string{"failedURL": mcUpdateURL})
|
||||
}
|
||||
latest, _ := time.Parse(http.TimeFormat, updates.BuildDate)
|
||||
if latest.IsZero() {
|
||||
|
||||
+16
-17
@@ -25,14 +25,13 @@ 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/iodine"
|
||||
)
|
||||
|
||||
// getSource gets a reader from URL<
|
||||
func getSource(sourceURL string) (reader io.ReadCloser, length int64, err error) {
|
||||
sourceClnt, err := source2Client(sourceURL)
|
||||
if err != nil {
|
||||
return nil, 0, iodine.New(err, map[string]string{"failedURL": sourceURL})
|
||||
return nil, 0, NewIodine(err, map[string]string{"failedURL": sourceURL})
|
||||
}
|
||||
return sourceClnt.GetObject(0, 0)
|
||||
}
|
||||
@@ -41,11 +40,11 @@ func getSource(sourceURL string) (reader io.ReadCloser, length int64, err error)
|
||||
func putTarget(targetURL string, length int64, reader io.Reader) error {
|
||||
targetClnt, err := target2Client(targetURL)
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
return NewIodine(err, nil)
|
||||
}
|
||||
err = targetClnt.PutObject(length, reader)
|
||||
if err != nil {
|
||||
return iodine.New(err, map[string]string{"failedURL": targetURL})
|
||||
return NewIodine(err, map[string]string{"failedURL": targetURL})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -64,7 +63,7 @@ func putTargets(targetURLs []string, length int64, reader io.Reader) <-chan erro
|
||||
tgtReaders[i], tgtWriters[i] = io.Pipe()
|
||||
tgtClient, err := target2Client(targetURL)
|
||||
if err != nil {
|
||||
errorCh <- iodine.New(err, nil)
|
||||
errorCh <- NewIodine(err, nil)
|
||||
continue
|
||||
}
|
||||
tgtClients[i] = tgtClient
|
||||
@@ -90,7 +89,7 @@ func putTargets(targetURLs []string, length int64, reader io.Reader) <-chan erro
|
||||
defer wg.Done()
|
||||
err := targetClient.PutObject(length, reader)
|
||||
if err != nil {
|
||||
errorCh <- iodine.New(err, map[string]string{"failedURL": targetClient.URL().String()})
|
||||
errorCh <- NewIodine(err, map[string]string{"failedURL": targetClient.URL().String()})
|
||||
}
|
||||
}(tgtClients[i], tgtReaders[i], errorCh)
|
||||
}
|
||||
@@ -104,12 +103,12 @@ func putTargets(targetURLs []string, length int64, reader io.Reader) <-chan erro
|
||||
func getNewClient(urlStr string, auth *hostConfig) (clnt client.Client, err error) {
|
||||
url, err := client.Parse(urlStr)
|
||||
if err != nil {
|
||||
return nil, iodine.New(errInvalidURL{URL: urlStr}, map[string]string{"URL": urlStr})
|
||||
return nil, NewIodine(errInvalidURL{URL: urlStr}, map[string]string{"URL": urlStr})
|
||||
}
|
||||
switch url.Type {
|
||||
case client.Object: // Minio and S3 compatible object storage
|
||||
if auth == nil {
|
||||
return nil, iodine.New(errInvalidArgument{}, nil)
|
||||
return nil, NewIodine(errInvalidArgument{}, nil)
|
||||
}
|
||||
s3Config := new(s3.Config)
|
||||
s3Config.AccessKeyID = func() string {
|
||||
@@ -133,19 +132,19 @@ func getNewClient(urlStr string, auth *hostConfig) (clnt client.Client, err erro
|
||||
case client.Filesystem:
|
||||
return fs.New(urlStr)
|
||||
}
|
||||
return nil, iodine.New(errInvalidURL{URL: urlStr}, nil)
|
||||
return nil, NewIodine(errInvalidURL{URL: urlStr}, nil)
|
||||
}
|
||||
|
||||
// url2Stat - Returns client, config and its stat Content from the URL
|
||||
func url2Stat(urlStr string) (client client.Client, content *client.Content, err error) {
|
||||
client, err = url2Client(urlStr)
|
||||
if err != nil {
|
||||
return nil, nil, iodine.New(err, map[string]string{"URL": urlStr})
|
||||
return nil, nil, NewIodine(err, map[string]string{"URL": urlStr})
|
||||
}
|
||||
|
||||
content, err = client.Stat()
|
||||
if err != nil {
|
||||
return nil, nil, iodine.New(err, map[string]string{"URL": urlStr})
|
||||
return nil, nil, NewIodine(err, map[string]string{"URL": urlStr})
|
||||
}
|
||||
|
||||
return client, content, nil
|
||||
@@ -155,21 +154,21 @@ func url2Client(url string) (client.Client, error) {
|
||||
// Empty source arg?
|
||||
urlParse, err := client.Parse(url)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, map[string]string{"URL": url})
|
||||
return nil, NewIodine(err, map[string]string{"URL": url})
|
||||
}
|
||||
|
||||
if urlParse.Path == "" {
|
||||
return nil, iodine.New(errInvalidURL{URL: url}, map[string]string{"URL": url})
|
||||
return nil, NewIodine(errInvalidURL{URL: url}, map[string]string{"URL": url})
|
||||
}
|
||||
|
||||
urlonfig, err := getHostConfig(url)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, map[string]string{"URL": url})
|
||||
return nil, NewIodine(err, map[string]string{"URL": url})
|
||||
}
|
||||
|
||||
client, err := getNewClient(url, urlonfig)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, map[string]string{"URL": url})
|
||||
return nil, NewIodine(err, map[string]string{"URL": url})
|
||||
}
|
||||
|
||||
return client, nil
|
||||
@@ -179,7 +178,7 @@ func url2Client(url string) (client.Client, error) {
|
||||
func source2Client(sourceURL string) (client.Client, error) {
|
||||
sourceClient, err := url2Client(sourceURL)
|
||||
if err != nil {
|
||||
return nil, iodine.New(errInvalidSource{URL: sourceURL}, map[string]string{"URL": sourceURL})
|
||||
return nil, NewIodine(errInvalidSource{URL: sourceURL}, map[string]string{"URL": sourceURL})
|
||||
}
|
||||
return sourceClient, nil
|
||||
}
|
||||
@@ -188,7 +187,7 @@ func source2Client(sourceURL string) (client.Client, error) {
|
||||
func target2Client(targetURL string) (client.Client, error) {
|
||||
targetClient, err := url2Client(targetURL)
|
||||
if err != nil {
|
||||
return nil, iodine.New(errInvalidTarget{URL: targetURL}, map[string]string{"URL": targetURL})
|
||||
return nil, NewIodine(errInvalidTarget{URL: targetURL}, map[string]string{"URL": targetURL})
|
||||
}
|
||||
return targetClient, nil
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/quick"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
type configV1 struct {
|
||||
@@ -52,7 +51,7 @@ func getMcConfigDir() (string, error) {
|
||||
}
|
||||
u, err := user.Current()
|
||||
if err != nil {
|
||||
return "", iodine.New(err, nil)
|
||||
return "", NewIodine(err, nil)
|
||||
}
|
||||
// For windows the path is slightly different
|
||||
switch runtime.GOOS {
|
||||
@@ -76,11 +75,11 @@ func mustGetMcConfigDir() (configDir string) {
|
||||
func createMcConfigDir() error {
|
||||
p, err := getMcConfigDir()
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
return NewIodine(err, nil)
|
||||
}
|
||||
err = os.MkdirAll(p, 0700)
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
return NewIodine(err, nil)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -89,7 +88,7 @@ func createMcConfigDir() error {
|
||||
func getMcConfigPath() (string, error) {
|
||||
dir, err := getMcConfigDir()
|
||||
if err != nil {
|
||||
return "", iodine.New(err, nil)
|
||||
return "", NewIodine(err, nil)
|
||||
}
|
||||
return filepath.Join(dir, mcConfigFile), nil
|
||||
}
|
||||
@@ -106,12 +105,12 @@ func mustGetMcConfigPath() string {
|
||||
// getMcConfig - reads configuration file and returns config
|
||||
func getMcConfig() (*configV1, error) {
|
||||
if !isMcConfigExists() {
|
||||
return nil, iodine.New(errInvalidArgument{}, nil)
|
||||
return nil, NewIodine(errInvalidArgument{}, nil)
|
||||
}
|
||||
|
||||
configFile, err := getMcConfigPath()
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
return nil, NewIodine(err, nil)
|
||||
}
|
||||
|
||||
// Cached in private global variable.
|
||||
@@ -122,12 +121,12 @@ func getMcConfig() (*configV1, error) {
|
||||
conf := newConfigV1()
|
||||
qconf, err := quick.New(conf)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
return nil, NewIodine(err, nil)
|
||||
}
|
||||
|
||||
err = qconf.Load(configFile)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
return nil, NewIodine(err, nil)
|
||||
}
|
||||
cache.Put(qconf)
|
||||
return qconf.Data().(*configV1), nil
|
||||
@@ -160,14 +159,14 @@ func isMcConfigExists() bool {
|
||||
func writeConfig(config quick.Config) error {
|
||||
err := createMcConfigDir()
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
return NewIodine(err, nil)
|
||||
}
|
||||
configPath, err := getMcConfigPath()
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
return NewIodine(err, nil)
|
||||
}
|
||||
if err := config.Save(configPath); err != nil {
|
||||
return iodine.New(err, nil)
|
||||
return NewIodine(err, nil)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -216,7 +215,7 @@ func newConfig() (config quick.Config, err error) {
|
||||
conf.Aliases = aliases
|
||||
config, err = quick.New(conf)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
return nil, NewIodine(err, nil)
|
||||
}
|
||||
|
||||
return config, nil
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/minio/mc/pkg/client"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
//
|
||||
@@ -123,24 +122,24 @@ func prepareCopyURLsTypeA(sourceURL string, targetURL string) <-chan copyURLs {
|
||||
_, sourceContent, err := url2Stat(sourceURL)
|
||||
if err != nil {
|
||||
// Source does not exist or insufficient privileges.
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(err, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(err, nil)}
|
||||
return
|
||||
}
|
||||
if !sourceContent.Type.IsRegular() {
|
||||
// Source is not a regular file
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(errInvalidSource{URL: sourceURL}, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(errInvalidSource{URL: sourceURL}, nil)}
|
||||
return
|
||||
}
|
||||
targetClient, err := target2Client(targetURL)
|
||||
if err != nil {
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(err, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(err, nil)}
|
||||
return
|
||||
}
|
||||
// Target exists?
|
||||
targetContent, err := targetClient.Stat()
|
||||
if err == nil { // Target exists.
|
||||
if !targetContent.Type.IsRegular() { // Target is not a regular file
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(errInvalidTarget{URL: targetURL}, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(errInvalidTarget{URL: targetURL}, nil)}
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -160,25 +159,25 @@ func prepareCopyURLsTypeB(sourceURL string, targetURL string) <-chan copyURLs {
|
||||
_, sourceContent, err := url2Stat(sourceURL)
|
||||
if err != nil {
|
||||
// Source does not exist or insufficient privileges.
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(err, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(err, nil)}
|
||||
return
|
||||
}
|
||||
|
||||
if !sourceContent.Type.IsRegular() {
|
||||
// Source is not a regular file.
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(errInvalidSource{URL: sourceURL}, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(errInvalidSource{URL: sourceURL}, nil)}
|
||||
return
|
||||
}
|
||||
|
||||
_, targetContent, err := url2Stat(targetURL)
|
||||
if err != nil {
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(err, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(err, nil)}
|
||||
return
|
||||
}
|
||||
if err == nil {
|
||||
if !targetContent.Type.IsDir() {
|
||||
// Target exists, but is not a directory.
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(errTargetIsNotDir{URL: targetURL}, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(errTargetIsNotDir{URL: targetURL}, nil)}
|
||||
return
|
||||
}
|
||||
} // Else name is available to create.
|
||||
@@ -186,13 +185,13 @@ func prepareCopyURLsTypeB(sourceURL string, targetURL string) <-chan copyURLs {
|
||||
// All OK.. We can proceed. Type B: source is a file, target is a directory and exists.
|
||||
sourceURLParse, err := client.Parse(sourceURL)
|
||||
if err != nil {
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(errInvalidSource{URL: sourceURL}, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(errInvalidSource{URL: sourceURL}, nil)}
|
||||
return
|
||||
}
|
||||
|
||||
targetURLParse, err := client.Parse(targetURL)
|
||||
if err != nil {
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(errInvalidTarget{URL: targetURL}, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(errInvalidTarget{URL: targetURL}, nil)}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -212,7 +211,7 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs {
|
||||
defer close(copyURLsCh)
|
||||
if !isURLRecursive(sourceURL) {
|
||||
// Source is not of recursive type.
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(errSourceNotRecursive{URL: sourceURL}, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(errSourceNotRecursive{URL: sourceURL}, nil)}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -221,13 +220,13 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs {
|
||||
sourceClient, sourceContent, err := url2Stat(sourceURL)
|
||||
if err != nil {
|
||||
// Source does not exist or insufficient privileges.
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(err, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(err, nil)}
|
||||
return
|
||||
}
|
||||
|
||||
if !sourceContent.Type.IsDir() {
|
||||
// Source is not a dir.
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(errSourceIsNotDir{URL: sourceURL}, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(errSourceIsNotDir{URL: sourceURL}, nil)}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -235,20 +234,20 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs {
|
||||
// Target exist?
|
||||
if err != nil {
|
||||
// Target does not exist.
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(errTargetNotFound{URL: targetURL}, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(errTargetNotFound{URL: targetURL}, nil)}
|
||||
return
|
||||
}
|
||||
|
||||
if !targetContent.Type.IsDir() {
|
||||
// Target exists, but is not a directory.
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(errTargetIsNotDir{URL: targetURL}, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(errTargetIsNotDir{URL: targetURL}, nil)}
|
||||
return
|
||||
}
|
||||
|
||||
for sourceContent := range sourceClient.List(true) {
|
||||
if sourceContent.Err != nil {
|
||||
// Listing failed.
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(sourceContent.Err, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(sourceContent.Err, nil)}
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -260,13 +259,13 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs {
|
||||
// All OK.. We can proceed. Type B: source is a file, target is a directory and exists.
|
||||
sourceURLParse, err := client.Parse(sourceURL)
|
||||
if err != nil {
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(errInvalidSource{URL: sourceURL}, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(errInvalidSource{URL: sourceURL}, nil)}
|
||||
continue
|
||||
}
|
||||
|
||||
targetURLParse, err := client.Parse(targetURL)
|
||||
if err != nil {
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(errInvalidTarget{URL: targetURL}, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(errInvalidTarget{URL: targetURL}, nil)}
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -276,7 +275,7 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs {
|
||||
sourceContentURL := sourceURLDelimited + sourceContentName
|
||||
sourceContentParse, err := client.Parse(sourceContentURL)
|
||||
if err != nil {
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(errInvalidSource{URL: sourceContentName}, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(errInvalidSource{URL: sourceContentName}, nil)}
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -301,7 +300,7 @@ func prepareCopyURLsTypeD(sourceURLs []string, targetURL string) <-chan copyURLs
|
||||
|
||||
if sourceURLs == nil {
|
||||
// Source list is empty.
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(errSourceListEmpty{}, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(errSourceListEmpty{}, nil)}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -309,13 +308,13 @@ func prepareCopyURLsTypeD(sourceURLs []string, targetURL string) <-chan copyURLs
|
||||
// Target exist?
|
||||
if err != nil {
|
||||
// Target does not exist.
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(errTargetNotFound{URL: targetURL}, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(errTargetNotFound{URL: targetURL}, nil)}
|
||||
return
|
||||
}
|
||||
|
||||
if !targetContent.Type.IsDir() {
|
||||
// Target exists, but is not a directory.
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(errTargetIsNotDir{URL: targetURL}, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(errTargetIsNotDir{URL: targetURL}, nil)}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -360,7 +359,7 @@ func prepareCopyURLs(sourceURLs []string, targetURL string) <-chan copyURLs {
|
||||
copyURLsCh <- cURLs
|
||||
}
|
||||
default:
|
||||
copyURLsCh <- copyURLs{Error: iodine.New(errInvalidArgument{}, nil)}
|
||||
copyURLsCh <- copyURLs{Error: NewIodine(errInvalidArgument{}, nil)}
|
||||
}
|
||||
}(sourceURLs, targetURL, copyURLsCh)
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/minio/mc/pkg/client"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
//
|
||||
@@ -47,11 +46,11 @@ type diff struct {
|
||||
func urlJoinPath(url1, url2 string) (newURLStr string, err error) {
|
||||
u1, err := client.Parse(url1)
|
||||
if err != nil {
|
||||
return "", iodine.New(err, nil)
|
||||
return "", NewIodine(err, nil)
|
||||
}
|
||||
u2, err := client.Parse(url2)
|
||||
if err != nil {
|
||||
return "", iodine.New(err, nil)
|
||||
return "", NewIodine(err, nil)
|
||||
}
|
||||
u1.Path = filepath.Join(u1.Path, u2.Path)
|
||||
newURLStr = u1.String()
|
||||
@@ -91,7 +90,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: iodine.New(errNotAnObject{url: firstURL}, nil),
|
||||
err: NewIodine(errNotAnObject{url: firstURL}, nil),
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -109,7 +108,7 @@ func dodiffdirs(firstClnt client.Client, firstURL, secondURL string, recursive b
|
||||
if contentCh.Err != nil {
|
||||
ch <- diff{
|
||||
message: "Failed to list ‘" + firstURL + "’",
|
||||
err: iodine.New(contentCh.Err, nil),
|
||||
err: NewIodine(contentCh.Err, nil),
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -117,7 +116,7 @@ func dodiffdirs(firstClnt client.Client, firstURL, secondURL string, recursive b
|
||||
if err != nil {
|
||||
ch <- diff{
|
||||
message: "Unable to construct new URL from ‘" + firstURL + "’ using ‘" + contentCh.Content.Name + "’",
|
||||
err: iodine.New(err, nil),
|
||||
err: NewIodine(err, nil),
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -125,7 +124,7 @@ func dodiffdirs(firstClnt client.Client, firstURL, secondURL string, recursive b
|
||||
if err != nil {
|
||||
ch <- diff{
|
||||
message: "Unable to construct new URL from ‘" + secondURL + "’ using ‘" + contentCh.Content.Name + "’",
|
||||
err: iodine.New(err, nil),
|
||||
err: NewIodine(err, nil),
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -174,7 +173,7 @@ func doDiffDirs(firstURL, secondURL string, recursive bool, ch chan diff) {
|
||||
if err != nil {
|
||||
ch <- diff{
|
||||
message: "Failed to stat ‘" + firstURL + "’",
|
||||
err: iodine.New(err, nil),
|
||||
err: NewIodine(err, nil),
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -182,7 +181,7 @@ func doDiffDirs(firstURL, secondURL string, recursive bool, ch chan diff) {
|
||||
if err != nil {
|
||||
ch <- diff{
|
||||
message: "Failed to stat ‘" + secondURL + "’",
|
||||
err: iodine.New(err, nil),
|
||||
err: NewIodine(err, nil),
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -197,7 +196,7 @@ func doDiffDirs(firstURL, secondURL string, recursive bool, ch chan diff) {
|
||||
default:
|
||||
ch <- diff{
|
||||
message: "‘" + firstURL + "’ is not an object. Please report this bug with ‘--debug’ option.",
|
||||
err: iodine.New(errNotAnObject{url: firstURL}, nil),
|
||||
err: NewIodine(errNotAnObject{url: firstURL}, nil),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
+5
-6
@@ -22,7 +22,6 @@ import (
|
||||
|
||||
"github.com/minio/mc/pkg/client"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
type hostConfig struct {
|
||||
@@ -34,11 +33,11 @@ type hostConfig struct {
|
||||
func getHostConfig(URL string) (*hostConfig, error) {
|
||||
config, err := getMcConfig()
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
return nil, NewIodine(err, nil)
|
||||
}
|
||||
url, err := client.Parse(URL)
|
||||
if err != nil {
|
||||
return nil, iodine.New(errInvalidURL{URL: URL}, nil)
|
||||
return nil, NewIodine(errInvalidURL{URL: URL}, nil)
|
||||
}
|
||||
// No host matching or keys needed for filesystem requests
|
||||
if url.Type == client.Filesystem {
|
||||
@@ -59,16 +58,16 @@ func getHostConfig(URL string) (*hostConfig, error) {
|
||||
for globURL, hostCfg := range config.Hosts {
|
||||
match, err := filepath.Match(globURL, url.Host)
|
||||
if err != nil {
|
||||
return nil, iodine.New(errInvalidGlobURL{glob: globURL, request: URL}, nil)
|
||||
return nil, NewIodine(errInvalidGlobURL{glob: globURL, request: URL}, nil)
|
||||
}
|
||||
if match {
|
||||
if hostCfg == nil {
|
||||
return nil, iodine.New(errInvalidAuth{}, nil)
|
||||
return nil, NewIodine(errInvalidAuth{}, nil)
|
||||
}
|
||||
return hostCfg, nil
|
||||
}
|
||||
}
|
||||
return nil, iodine.New(errNoMatchingHost{}, nil)
|
||||
return nil, NewIodine(errNoMatchingHost{}, nil)
|
||||
}
|
||||
|
||||
// mustGetHostConfig retrieves host specific configuration such as access keys, exits upon error
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* Minio Client (C) 2014, 2015 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
// Error is the iodine error which contains a pointer to the original error
|
||||
// and stack traces.
|
||||
type Error struct {
|
||||
EmbeddedError error `json:"-"`
|
||||
ErrorMessage string
|
||||
ErrorType string
|
||||
|
||||
Stack []StackEntry
|
||||
}
|
||||
|
||||
// StackEntry contains the entry in the stack trace
|
||||
type StackEntry struct {
|
||||
Host string
|
||||
File string
|
||||
Func string
|
||||
Line int
|
||||
Data map[string]string
|
||||
}
|
||||
|
||||
// NewIodine - instantiate an error, turning it into an iodine error.
|
||||
// Adds an initial stack trace.
|
||||
func NewIodine(err error, data map[string]string) error {
|
||||
_, iodineFile, _, _ := runtime.Caller(0)
|
||||
iodineFile = filepath.Dir(iodineFile) // trim iodine.go
|
||||
iodineFile = filepath.Dir(iodineFile) // trim iodine
|
||||
iodineFile = filepath.Dir(iodineFile) // trim pkg
|
||||
iodineFile = filepath.Dir(iodineFile) // trim minio
|
||||
iodineFile = filepath.Dir(iodineFile) // trim minio
|
||||
gopathSource = filepath.Dir(iodineFile) + "/" // trim github.com
|
||||
|
||||
if err != nil {
|
||||
entry := createStackEntry()
|
||||
var newErr Error
|
||||
|
||||
// check if error is wrapped
|
||||
switch typedError := err.(type) {
|
||||
case Error:
|
||||
{
|
||||
newErr = typedError
|
||||
}
|
||||
default:
|
||||
{
|
||||
newErr = Error{
|
||||
EmbeddedError: err,
|
||||
ErrorMessage: err.Error(),
|
||||
ErrorType: reflect.TypeOf(err).String(),
|
||||
Stack: []StackEntry{},
|
||||
}
|
||||
}
|
||||
}
|
||||
for k, v := range data {
|
||||
entry.Data[k] = v
|
||||
}
|
||||
newErr.Stack = append(newErr.Stack, entry)
|
||||
return newErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var gopathSource string
|
||||
|
||||
// createStackEntry - create stack entries
|
||||
func createStackEntry() StackEntry {
|
||||
host, _ := os.Hostname()
|
||||
pc, file, line, _ := runtime.Caller(2)
|
||||
function := runtime.FuncForPC(pc).Name()
|
||||
_, function = filepath.Split(function)
|
||||
file = strings.TrimPrefix(file, gopathSource) // trim gopathSource from file
|
||||
|
||||
data := make(map[string]string)
|
||||
for k, v := range getIodineSystemData() {
|
||||
data[k] = v
|
||||
}
|
||||
|
||||
entry := StackEntry{
|
||||
Host: host,
|
||||
File: file,
|
||||
Func: function,
|
||||
Line: line,
|
||||
Data: data,
|
||||
}
|
||||
return entry
|
||||
}
|
||||
|
||||
func getIodineSystemData() map[string]string {
|
||||
host, err := os.Hostname()
|
||||
if err != nil {
|
||||
host = ""
|
||||
}
|
||||
memstats := &runtime.MemStats{}
|
||||
runtime.ReadMemStats(memstats)
|
||||
return map[string]string{
|
||||
"sys.host": host,
|
||||
"sys.os": runtime.GOOS,
|
||||
"sys.arch": runtime.GOARCH,
|
||||
"sys.go": runtime.Version(),
|
||||
"sys.cpus": strconv.Itoa(runtime.NumCPU()),
|
||||
"sys.mem.used": humanize.Bytes(memstats.Alloc),
|
||||
"sys.mem.allocated": humanize.Bytes(memstats.TotalAlloc),
|
||||
"sys.mem.heap.used": humanize.Bytes(memstats.HeapAlloc),
|
||||
"sys.mem.heap.allocated": humanize.Bytes(memstats.HeapSys),
|
||||
}
|
||||
}
|
||||
|
||||
// ToError returns the input if it is not an iodine error. It returns the embedded error if it is an iodine error. If nil, returns nil.
|
||||
func ToError(err error) error {
|
||||
switch err := err.(type) {
|
||||
case nil:
|
||||
{
|
||||
return nil
|
||||
}
|
||||
case Error:
|
||||
{
|
||||
if err.EmbeddedError != nil {
|
||||
return err.EmbeddedError
|
||||
}
|
||||
return errors.New(err.ErrorMessage)
|
||||
}
|
||||
default:
|
||||
{
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// EmitHumanReadable returns a human readable error message
|
||||
func (err Error) EmitHumanReadable() string {
|
||||
var errorBuffer bytes.Buffer
|
||||
if globalDebugFlag {
|
||||
fmt.Fprint(&errorBuffer, err.ErrorMessage)
|
||||
for i, entry := range err.Stack {
|
||||
prettyData, _ := json.Marshal(entry.Data)
|
||||
fmt.Fprintln(&errorBuffer, "-", i, entry.Host+":"+entry.File+":"+strconv.Itoa(entry.Line)+" "+entry.Func+"():", string(prettyData))
|
||||
}
|
||||
} else {
|
||||
fmt.Fprint(&errorBuffer, iodine.ToError(err.EmbeddedError))
|
||||
}
|
||||
return string(errorBuffer.Bytes())
|
||||
}
|
||||
|
||||
// Emits the original error message
|
||||
func (err Error) Error() string {
|
||||
return err.EmitHumanReadable()
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/minio/mc/pkg/client"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
/// ls - related internal functions
|
||||
@@ -76,13 +75,13 @@ func doList(clnt client.Client, recursive bool) error {
|
||||
var err error
|
||||
for contentCh := range clnt.List(recursive) {
|
||||
if contentCh.Err != nil {
|
||||
switch err := iodine.ToError(contentCh.Err).(type) {
|
||||
switch err := ToError(contentCh.Err).(type) {
|
||||
// handle this specifically for filesystem
|
||||
case client.ISBrokenSymlink:
|
||||
console.Errorf(err.Error())
|
||||
continue
|
||||
}
|
||||
if os.IsNotExist(iodine.ToError(contentCh.Err)) || os.IsPermission(iodine.ToError(contentCh.Err)) {
|
||||
if os.IsNotExist(ToError(contentCh.Err)) || os.IsPermission(ToError(contentCh.Err)) {
|
||||
console.Errorf(contentCh.Err.Error())
|
||||
continue
|
||||
}
|
||||
@@ -92,7 +91,7 @@ func doList(clnt client.Client, recursive bool) error {
|
||||
console.Prints(parseContent(contentCh.Content))
|
||||
}
|
||||
if err != nil {
|
||||
return iodine.New(err, map[string]string{"Target": clnt.URL().String()})
|
||||
return NewIodine(err, map[string]string{"Target": clnt.URL().String()})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
+6
-7
@@ -26,7 +26,6 @@ import (
|
||||
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/quick"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
type sessionV1 struct {
|
||||
@@ -50,13 +49,13 @@ func (s sessionV1) String() string {
|
||||
// loadSession - reads session file if exists and re-initiates internal variables
|
||||
func loadSessionV1(sid string) (*sessionV1, error) {
|
||||
if !isSessionDirExists() {
|
||||
return nil, iodine.New(errInvalidArgument{}, nil)
|
||||
return nil, NewIodine(errInvalidArgument{}, nil)
|
||||
}
|
||||
sessionFile := getSessionFileV1(sid)
|
||||
|
||||
_, err := os.Stat(sessionFile)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
return nil, NewIodine(err, nil)
|
||||
}
|
||||
s := new(sessionV1)
|
||||
s.Version = "1.0.0"
|
||||
@@ -66,11 +65,11 @@ func loadSessionV1(sid string) (*sessionV1, error) {
|
||||
s.Files = make(map[string]bool)
|
||||
qs, err := quick.New(s)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
return nil, NewIodine(err, nil)
|
||||
}
|
||||
err = qs.Load(sessionFile)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
return nil, NewIodine(err, nil)
|
||||
}
|
||||
return qs.Data().(*sessionV1), nil
|
||||
}
|
||||
@@ -78,7 +77,7 @@ func loadSessionV1(sid string) (*sessionV1, error) {
|
||||
func getSessionIDsV1() (sids []string) {
|
||||
sessionList, err := filepath.Glob(getSessionDir() + "/*")
|
||||
if err != nil {
|
||||
console.Fatalf("Unable to list session directory ‘%s’, %s", getSessionDir(), iodine.New(err, nil))
|
||||
console.Fatalf("Unable to list session directory ‘%s’, %s", getSessionDir(), NewIodine(err, nil))
|
||||
}
|
||||
|
||||
for _, path := range sessionList {
|
||||
@@ -87,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, iodine.New(err, nil))
|
||||
console.Fatalf("Unable to load session ‘%s’, %s", sid, NewIodine(err, nil))
|
||||
}
|
||||
if sessionV1.Version != "1.0.0" {
|
||||
continue
|
||||
|
||||
+11
-12
@@ -27,7 +27,6 @@ import (
|
||||
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/quick"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
// migrateSessionV1ToV2 migrates all session files from v1 to v2. This
|
||||
@@ -37,7 +36,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), iodine.New(err, nil))
|
||||
console.Fatalf("Migration failed. Unable to remove old session file %s. %s\n", getSessionFileV1(sid), NewIodine(err, nil))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,12 +122,12 @@ func (s *sessionV2) Save() error {
|
||||
|
||||
err := s.DataFP.Sync()
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
return NewIodine(err, nil)
|
||||
}
|
||||
|
||||
qs, err := quick.New(s.Header)
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
return NewIodine(err, nil)
|
||||
}
|
||||
|
||||
return qs.Save(getSessionFile(s.SessionID))
|
||||
@@ -141,21 +140,21 @@ func (s *sessionV2) Close() error {
|
||||
|
||||
err := s.DataFP.Close()
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
return NewIodine(err, nil)
|
||||
}
|
||||
|
||||
err = os.Remove(getSessionDataFile(s.SessionID))
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
return NewIodine(err, nil)
|
||||
}
|
||||
|
||||
err = os.Remove(getSessionFile(s.SessionID))
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
return NewIodine(err, nil)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
return NewIodine(err, nil)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -163,13 +162,13 @@ func (s *sessionV2) Close() error {
|
||||
// loadSession - reads session file if exists and re-initiates internal variables
|
||||
func loadSessionV2(sid string) (*sessionV2, error) {
|
||||
if !isSessionDirExists() {
|
||||
return nil, iodine.New(errInvalidArgument{}, nil)
|
||||
return nil, NewIodine(errInvalidArgument{}, nil)
|
||||
}
|
||||
sessionFile := getSessionFile(sid)
|
||||
|
||||
_, err := os.Stat(sessionFile)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
return nil, NewIodine(err, nil)
|
||||
}
|
||||
|
||||
s := &sessionV2{}
|
||||
@@ -178,11 +177,11 @@ func loadSessionV2(sid string) (*sessionV2, error) {
|
||||
s.Header.Version = "1.1.0"
|
||||
qs, err := quick.New(s.Header)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
return nil, NewIodine(err, nil)
|
||||
}
|
||||
err = qs.Load(sessionFile)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
return nil, NewIodine(err, nil)
|
||||
}
|
||||
|
||||
s.mutex = new(sync.Mutex)
|
||||
|
||||
+2
-3
@@ -24,7 +24,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
func migrateSession() {
|
||||
@@ -42,7 +41,7 @@ func isSessionDirExists() bool {
|
||||
|
||||
func createSessionDir() error {
|
||||
if err := os.MkdirAll(getSessionDir(), 0700); err != nil {
|
||||
return iodine.New(err, nil)
|
||||
return NewIodine(err, nil)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -78,7 +77,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 directory ‘%s’, %s", getSessionDir(), iodine.New(err, nil))
|
||||
console.Fatalf("Unable to list session directory ‘%s’, %s", getSessionDir(), NewIodine(err, nil))
|
||||
}
|
||||
|
||||
for _, path := range sessionList {
|
||||
|
||||
+12
-13
@@ -21,7 +21,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/minio/mc/pkg/client"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
//
|
||||
@@ -100,7 +99,7 @@ func prepareSyncURLsTypeA(sourceURL string, targetURLs []string) <-chan syncURLs
|
||||
var cURLs copyURLs
|
||||
for cURLs = range prepareCopyURLsTypeA(sourceURL, targetURL) {
|
||||
if cURLs.Error != nil {
|
||||
syncURLsCh <- syncURLs{Error: iodine.New(cURLs.Error, nil)}
|
||||
syncURLsCh <- syncURLs{Error: NewIodine(cURLs.Error, nil)}
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -124,7 +123,7 @@ func prepareSyncURLsTypeB(sourceURL string, targetURLs []string) <-chan syncURLs
|
||||
var cURLs copyURLs
|
||||
for cURLs = range prepareCopyURLsTypeB(sourceURL, targetURL) {
|
||||
if cURLs.Error != nil {
|
||||
syncURLsCh <- syncURLs{Error: iodine.New(cURLs.Error, nil)}
|
||||
syncURLsCh <- syncURLs{Error: NewIodine(cURLs.Error, nil)}
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -145,7 +144,7 @@ func prepareSyncURLsTypeC(sourceURL string, targetURLs []string) <-chan syncURLs
|
||||
defer close(syncURLsCh)
|
||||
if !isURLRecursive(sourceURL) {
|
||||
// Source is not of recursive type.
|
||||
syncURLsCh <- syncURLs{Error: iodine.New(errSourceNotRecursive{URL: sourceURL}, nil)}
|
||||
syncURLsCh <- syncURLs{Error: NewIodine(errSourceNotRecursive{URL: sourceURL}, nil)}
|
||||
return
|
||||
}
|
||||
// add `/` after trimming off `...` to emulate directories
|
||||
@@ -154,13 +153,13 @@ func prepareSyncURLsTypeC(sourceURL string, targetURLs []string) <-chan syncURLs
|
||||
// Source exist?
|
||||
if err != nil {
|
||||
// Source does not exist or insufficient privileges.
|
||||
syncURLsCh <- syncURLs{Error: iodine.New(err, nil)}
|
||||
syncURLsCh <- syncURLs{Error: NewIodine(err, nil)}
|
||||
return
|
||||
}
|
||||
|
||||
if !sourceContent.Type.IsDir() {
|
||||
// Source is not a dir.
|
||||
syncURLsCh <- syncURLs{Error: iodine.New(errSourceIsNotDir{URL: sourceURL}, nil)}
|
||||
syncURLsCh <- syncURLs{Error: NewIodine(errSourceIsNotDir{URL: sourceURL}, nil)}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -169,20 +168,20 @@ func prepareSyncURLsTypeC(sourceURL string, targetURLs []string) <-chan syncURLs
|
||||
// Target exist?
|
||||
if err != nil {
|
||||
// Target does not exist.
|
||||
syncURLsCh <- syncURLs{Error: iodine.New(errTargetNotFound{URL: targetURL}, nil)}
|
||||
syncURLsCh <- syncURLs{Error: NewIodine(errTargetNotFound{URL: targetURL}, nil)}
|
||||
return
|
||||
}
|
||||
|
||||
if !targetContent.Type.IsDir() {
|
||||
// Target exists, but is not a directory.
|
||||
syncURLsCh <- syncURLs{Error: iodine.New(errTargetIsNotDir{URL: targetURL}, nil)}
|
||||
syncURLsCh <- syncURLs{Error: NewIodine(errTargetIsNotDir{URL: targetURL}, nil)}
|
||||
return
|
||||
}
|
||||
}
|
||||
for sourceContent := range sourceClient.List(true) {
|
||||
if sourceContent.Err != nil {
|
||||
// Listing failed.
|
||||
syncURLsCh <- syncURLs{Error: iodine.New(sourceContent.Err, nil)}
|
||||
syncURLsCh <- syncURLs{Error: NewIodine(sourceContent.Err, nil)}
|
||||
continue
|
||||
}
|
||||
if !sourceContent.Content.Type.IsRegular() {
|
||||
@@ -192,7 +191,7 @@ func prepareSyncURLsTypeC(sourceURL string, targetURLs []string) <-chan syncURLs
|
||||
// All OK.. We can proceed. Type B: source is a file, target is a directory and exists.
|
||||
sourceURLParse, err := client.Parse(sourceURL)
|
||||
if err != nil {
|
||||
syncURLsCh <- syncURLs{Error: iodine.New(errInvalidSource{URL: sourceURL}, nil)}
|
||||
syncURLsCh <- syncURLs{Error: NewIodine(errInvalidSource{URL: sourceURL}, nil)}
|
||||
continue
|
||||
}
|
||||
var newTargetURLs []string
|
||||
@@ -200,7 +199,7 @@ func prepareSyncURLsTypeC(sourceURL string, targetURLs []string) <-chan syncURLs
|
||||
for _, targetURL := range targetURLs {
|
||||
targetURLParse, err := client.Parse(targetURL)
|
||||
if err != nil {
|
||||
syncURLsCh <- syncURLs{Error: iodine.New(errInvalidTarget{URL: targetURL}, nil)}
|
||||
syncURLsCh <- syncURLs{Error: NewIodine(errInvalidTarget{URL: targetURL}, nil)}
|
||||
continue
|
||||
}
|
||||
sourceURLDelimited := sourceURLParse.String()[:strings.LastIndex(sourceURLParse.String(),
|
||||
@@ -209,7 +208,7 @@ func prepareSyncURLsTypeC(sourceURL string, targetURLs []string) <-chan syncURLs
|
||||
sourceContentURL := sourceURLDelimited + sourceContentName
|
||||
sourceContentParse, err = client.Parse(sourceContentURL)
|
||||
if err != nil {
|
||||
syncURLsCh <- syncURLs{Error: iodine.New(errInvalidSource{URL: sourceContentName}, nil)}
|
||||
syncURLsCh <- syncURLs{Error: NewIodine(errInvalidSource{URL: sourceContentName}, nil)}
|
||||
continue
|
||||
}
|
||||
// Construct target path from recursive path of source without its prefix dir.
|
||||
@@ -244,7 +243,7 @@ func prepareSyncURLs(sourceURL string, targetURLs []string) <-chan syncURLs {
|
||||
syncURLsCh <- sURLs
|
||||
}
|
||||
default:
|
||||
syncURLsCh <- syncURLs{Error: iodine.New(errInvalidArgument{}, nil)}
|
||||
syncURLsCh <- syncURLs{Error: NewIodine(errInvalidArgument{}, nil)}
|
||||
}
|
||||
}()
|
||||
return syncURLsCh
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/minio/mc/pkg/client"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
// ``...`` recursiveSeparator
|
||||
@@ -49,16 +48,16 @@ func stripRecursiveURL(urlStr string) string {
|
||||
func getExpandedURL(arg string, aliases map[string]string) (urlStr string, err error) {
|
||||
if _, err := client.Parse(urlStr); err != nil {
|
||||
// Not a valid URL. Return error
|
||||
return "", iodine.New(errInvalidURL{arg}, nil)
|
||||
return "", NewIodine(errInvalidURL{arg}, nil)
|
||||
}
|
||||
// Check and expand Alias
|
||||
urlStr, err = aliasExpand(arg, aliases)
|
||||
if err != nil {
|
||||
return "", iodine.New(err, nil)
|
||||
return "", NewIodine(err, nil)
|
||||
}
|
||||
if _, err := client.Parse(urlStr); err != nil {
|
||||
// Not a valid URL. Return error
|
||||
return "", iodine.New(errInvalidURL{urlStr}, nil)
|
||||
return "", NewIodine(errInvalidURL{urlStr}, nil)
|
||||
}
|
||||
return urlStr, nil
|
||||
}
|
||||
@@ -68,7 +67,7 @@ func getExpandedURLs(args []string, aliases map[string]string) (urls []string, e
|
||||
for _, arg := range args {
|
||||
u, err := getExpandedURL(arg, aliases)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
return nil, NewIodine(err, nil)
|
||||
}
|
||||
urls = append(urls, u)
|
||||
}
|
||||
@@ -79,12 +78,12 @@ func getExpandedURLs(args []string, aliases map[string]string) (urls []string, e
|
||||
func args2URLs(args []string) ([]string, error) {
|
||||
config, err := getMcConfig()
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
return nil, NewIodine(err, nil)
|
||||
}
|
||||
// Convert arguments to URLs: expand alias, fix format...
|
||||
URLs, err := getExpandedURLs(args, config.Aliases)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
return nil, NewIodine(err, nil)
|
||||
}
|
||||
return URLs, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user