diff --git a/cmd-mb.go b/cmd-mb.go index c666768d..06bd2c85 100644 --- a/cmd-mb.go +++ b/cmd-mb.go @@ -43,16 +43,20 @@ func doMakeBucketCmd(ctx *cli.Context) { bucket, _, err := url2Object(u) if err != nil { log.Debug.Println(iodine.New(err, nil)) - console.Fatalf("mc: Unable to decode bucket and object from URL[%s]\n", u) + console.Fatalf("mc: Unable to decode bucket and object from URL [%s]\n", u) } // this is handled differently since http based URLs cannot have // nested directories as buckets, buckets are a unique alphanumeric // name having subdirectories is only supported for fsClient if getURLType(u) != urlFS { + if bucket == "" { + log.Debug.Println(iodine.New(errBucketNameEmpty{}, nil)) + console.Fatalln("mc: bucket name empty") + } if !client.IsValidBucketName(bucket) { - log.Debug.Println(iodine.New(err, nil)) - console.Fatalf("mc: Invalid bucket name: %s", bucket) + log.Debug.Println(iodine.New(errInvalidBucketName{bucket: bucket}, nil)) + console.Fatalf("mc: Invalid bucket name: [%s]\n", bucket) } } @@ -66,14 +70,13 @@ func doMakeBucketCmd(ctx *cli.Context) { // retry - 5 times for r := retries.init(); r.retry(); { err = clnt.PutBucket(bucket) - if !isValidRetry(err) { break } } if err != nil { log.Debug.Println(iodine.New(err, nil)) - // error message returned properly by PutBucket() + console.Infoln() console.Fatalln(err) } } diff --git a/errors.go b/errors.go index 8302e608..56a17a29 100644 --- a/errors.go +++ b/errors.go @@ -90,12 +90,27 @@ type errAliasNotFound struct { } func (e errAliasNotFound) Error() string { - return fmt.Sprintf("alias: %s exists", e.name) + return "alias: " + e.name + " exists" } // errInvalidAuthKeys - invalid authorization keys type errInvalidAuthKeys struct{} func (e errInvalidAuthKeys) Error() string { - return fmt.Sprintf("invalid authorization keys") + return "invalid authorization keys" +} + +// errInvalidBucketName - invalid bucket name +type errInvalidBucketName struct { + bucket string +} + +func (e errInvalidBucketName) Error() string { + return "invalid bucket name: " + e.bucket +} + +type errBucketNameEmpty struct{} + +func (e errBucketNameEmpty) Error() string { + return "bucket name empty" } diff --git a/pkg/client/s3/errors.go b/pkg/client/s3/errors.go index d635bfcd..b05ef898 100644 --- a/pkg/client/s3/errors.go +++ b/pkg/client/s3/errors.go @@ -56,5 +56,6 @@ func NewError(res *http.Response) error { // Error formats HTTP error string func (e *Error) Error() string { - return fmt.Sprintf("%s", e.response.Status) + message, _ := e.responseMap.ValuesForKey("Message") + return fmt.Sprintf("[%s] server replied with Message: %s", e.response.Header.Get("Server"), message) }