diff --git a/cmd/config-host-add.go b/cmd/config-host-add.go index 98f4290a..9bed03f4 100644 --- a/cmd/config-host-add.go +++ b/cmd/config-host-add.go @@ -72,12 +72,11 @@ func checkConfigHostAddSyntax(ctx *cli.Context) { api := args.Get(4) if !isValidAlias(alias) { - fatalIf(errDummy().Trace(alias), "Invalid alias `"+alias+"`.") + fatalIf(errInvalidAlias(alias), "Invalid alias") } if !isValidHostURL(url) { - fatalIf(errDummy().Trace(url), - "Invalid URL `"+url+"`.") + fatalIf(errInvalidURL(url), "Invalid URL.") } if !isValidAccessKey(accessKey) { diff --git a/cmd/config-validate.go b/cmd/config-validate.go index c9476484..adab5924 100644 --- a/cmd/config-validate.go +++ b/cmd/config-validate.go @@ -17,7 +17,6 @@ package cmd import ( - "bytes" "fmt" "strings" ) @@ -54,25 +53,13 @@ func validateConfigFile(config *configV8) (bool, []string) { func validateConfigHost(host hostConfigV8) (bool, []string) { var validationSuccessful = true var hostErrors []string - api := host.API - validAPI := isValidAPI(strings.ToLower(api)) - if !validAPI { - var errorMsg bytes.Buffer - errorMsg.WriteString(fmt.Sprintf( - "%s API for host %s is not Valid. It is not part of any of the following APIs:\n", - api, host.URL)) - for index, validAPI := range validAPIs { - errorMsg.WriteString(fmt.Sprintf("%d. %s\n", index+1, validAPI)) - } + if !isValidAPI(strings.ToLower(host.API)) { validationSuccessful = false - hostErrors = append(hostErrors, errorMsg.String()) + hostErrors = append(hostErrors, errInvalidAPISignature(host.API, host.URL).ToGoError().Error()) } - url := host.URL - validURL := isValidHostURL(url) - if !validURL { + if !isValidHostURL(host.URL) { validationSuccessful = false - msg := fmt.Sprintf("URL %s for host %s is not valid. Could not parse it.\n", url, host.URL) - hostErrors = append(hostErrors, msg) + hostErrors = append(hostErrors, errInvalidURL(host.URL).ToGoError().Error()) } return validationSuccessful, hostErrors } diff --git a/cmd/main.go b/cmd/main.go index dc4af656..10b96c23 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -134,7 +134,7 @@ func checkConfig() { } errorMsg.WriteString(errMsg + "\n") } - console.Fatalln(errorMsg.String()) + console.Fatal(errorMsg.String()) } } diff --git a/cmd/typed-errors.go b/cmd/typed-errors.go index 37d08549..2a0fdad2 100644 --- a/cmd/typed-errors.go +++ b/cmd/typed-errors.go @@ -18,6 +18,8 @@ package cmd import ( "errors" + "fmt" + "strings" "github.com/minio/minio/pkg/probe" ) @@ -39,6 +41,21 @@ var ( return probe.NewError(errors.New("Use `mc config host add mycloud " + URL + " ...` to add an alias. Use the alias for S3 operations.")).Untrace() } + errInvalidAlias = func(alias string) *probe.Error { + return probe.NewError(errors.New("Alias `" + alias + "` should have alphanumeric characters such as [helloWorld0, hello_World0, ...]")) + } + + errInvalidURL = func(URL string) *probe.Error { + return probe.NewError(errors.New("URL `" + URL + "` for minio client should be of the form scheme://host[:port]/ without resource component.")) + } + + errInvalidAPISignature = func(api, url string) *probe.Error { + msg := fmt.Sprintf( + "Unrecognized API signature %s for host %s. Valid options are `[%s]`", + api, url, strings.Join(validAPIs, ", ")) + return probe.NewError(errors.New(msg)) + } + errNoMatchingHost = func(URL string) *probe.Error { return probe.NewError(errors.New("No matching host found for the given URL `" + URL + "`.")).Untrace() }