diff --git a/pkg/config/errors.go b/pkg/config/errors.go index 62b563cc4..914996a30 100644 --- a/pkg/config/errors.go +++ b/pkg/config/errors.go @@ -128,3 +128,44 @@ type ErrMissingPrimaryRepo struct { func (e ErrMissingPrimaryRepo) Error() string { return "Current context manifest must have primary repository set" } + +// ErrConflictingAuthOptions returned in case both token and username/password is set at same time +type ErrConflictingAuthOptions struct { +} + +func (e ErrConflictingAuthOptions) Error() string { + return "you cannot specify token and username/password at the same time" +} + +// ErrConflictingClusterOptions returned when both certificate-authority and +// insecure-skip-tls-verify is set at same time +type ErrConflictingClusterOptions struct { +} + +func (e ErrConflictingClusterOptions) Error() string { + return "you cannot specify a certificate-authority and insecure-skip-tls-verify mode at the same time" +} + +// ErrEmptyClusterName returned when empty cluster name is set +type ErrEmptyClusterName struct { +} + +func (e ErrEmptyClusterName) Error() string { + return "you must specify a non-empty cluster name" +} + +// ErrConflictingContextOptions returned when both context and --current is set at same time +type ErrConflictingContextOptions struct { +} + +func (e ErrConflictingContextOptions) Error() string { + return "you cannot specify context and --current Flag at the same time" +} + +// ErrEmptyContextName returned when empty context name is set +type ErrEmptyContextName struct { +} + +func (e ErrEmptyContextName) Error() string { + return "you must specify a non-empty context name" +} diff --git a/pkg/config/options.go b/pkg/config/options.go index 7f9c57b5d..54dc95411 100644 --- a/pkg/config/options.go +++ b/pkg/config/options.go @@ -16,10 +16,7 @@ limitations under the License. package config -// TODO(howell): Switch to strongly-typed errors - import ( - "errors" "fmt" "os" ) @@ -75,8 +72,7 @@ func (o *AuthInfoOptions) Validate() error { // already had a user/pass and visa-versa. This could create bugs if a // user at first chooses one method, but later switches to another. if o.Token != "" && (o.Username != "" || o.Password != "") { - // TODO(howell): strongly type this error - return errors.New("you must specify either token or a username/password") + return ErrConflictingAuthOptions{} } if !o.EmbedCertData { @@ -98,11 +94,11 @@ func (o *AuthInfoOptions) Validate() error { // Error when invalid value or incompatible choice of values given func (o *ContextOptions) Validate() error { if !o.Current && o.Name == "" { - return errors.New("you must specify a non-empty context name") + return ErrEmptyContextName{} } if o.Current && o.Name != "" { - return errors.New("you cannot specify context and --current Flag at the same time") + return ErrConflictingContextOptions{} } // If the user simply wants to change the current context, no further validation is needed @@ -125,7 +121,7 @@ func (o *ContextOptions) Validate() error { // Error when invalid value or incompatible choice of values given func (o *ClusterOptions) Validate() error { if o.Name == "" { - return errors.New("you must specify a non-empty cluster name") + return ErrEmptyClusterName{} } err := ValidClusterType(o.ClusterType) @@ -134,7 +130,7 @@ func (o *ClusterOptions) Validate() error { } if o.InsecureSkipTLSVerify && o.CertificateAuthority != "" { - return errors.New("you cannot specify a certificate-authority and insecure-skip-tls-verify mode at the same time") + return ErrConflictingClusterOptions{} } if !o.EmbedCAData {