1
0
mirror of https://github.com/minio/mc.git synced 2026-01-04 02:44:40 +03:00

Add mc top level error handling without printing stack traces.

This commit is contained in:
Harshavardhana
2015-07-15 16:32:20 -07:00
parent 1d76b592a3
commit ab4f64b5e3
22 changed files with 334 additions and 177 deletions

View File

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