github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+incompatible/command/errors.go (about)

     1  package command
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  type APIRequestError struct {
     9  	Err error
    10  }
    11  
    12  func (_ APIRequestError) Error() string {
    13  	return "Request error: {{.Error}}\nTIP: If you are behind a firewall and require an HTTP proxy, verify the https_proxy environment variable is correctly set. Else, check your network connection."
    14  }
    15  
    16  func (e APIRequestError) Translate(translate func(string, ...interface{}) string) string {
    17  	return translate(e.Error(), map[string]interface{}{
    18  		"Error": e.Err,
    19  	})
    20  }
    21  
    22  type BadCredentialsError struct{}
    23  
    24  func (_ BadCredentialsError) Error() string {
    25  	return "Credentials were rejected, please try again."
    26  }
    27  
    28  func (e BadCredentialsError) Translate(translate func(string, ...interface{}) string) string {
    29  	return translate(e.Error(), map[string]interface{}{})
    30  }
    31  
    32  type InvalidSSLCertError struct {
    33  	API string
    34  }
    35  
    36  func (_ InvalidSSLCertError) Error() string {
    37  	return "Invalid SSL Cert for {{.API}}\nTIP: Use 'cf api --skip-ssl-validation' to continue with an insecure API endpoint"
    38  }
    39  
    40  func (e InvalidSSLCertError) Translate(translate func(string, ...interface{}) string) string {
    41  	return translate(e.Error(), map[string]interface{}{
    42  		"API": e.API,
    43  	})
    44  }
    45  
    46  type SSLCertErrorError struct {
    47  	Message string
    48  }
    49  
    50  func (_ SSLCertErrorError) Error() string {
    51  	return "SSL Certificate Error {{.Message}}\nTIP: Use 'cf api --skip-ssl-validation' to continue with an insecure API endpoint"
    52  }
    53  
    54  func (e SSLCertErrorError) Translate(translate func(string, ...interface{}) string) string {
    55  	return translate(e.Error(), map[string]interface{}{
    56  		"Message": e.Message,
    57  	})
    58  }
    59  
    60  type NoAPISetError struct {
    61  	BinaryName string
    62  }
    63  
    64  func (_ NoAPISetError) Error() string {
    65  	return "No API endpoint set. Use '{{.LoginTip}}' or '{{.APITip}}' to target an endpoint."
    66  }
    67  
    68  func (e NoAPISetError) Translate(translate func(string, ...interface{}) string) string {
    69  	return translate(e.Error(), map[string]interface{}{
    70  		"LoginTip": fmt.Sprintf("%s login", e.BinaryName),
    71  		"APITip":   fmt.Sprintf("%s api", e.BinaryName),
    72  	})
    73  }
    74  
    75  type NotLoggedInError struct {
    76  	BinaryName string
    77  }
    78  
    79  func (_ NotLoggedInError) Error() string {
    80  	return "Not logged in. Use '{{.CFLoginCommand}}' to log in."
    81  }
    82  
    83  func (e NotLoggedInError) Translate(translate func(string, ...interface{}) string) string {
    84  	return translate(e.Error(), map[string]interface{}{
    85  		"CFLoginCommand": fmt.Sprintf("%s login", e.BinaryName),
    86  	})
    87  }
    88  
    89  type NoOrganizationTargetedError struct {
    90  	BinaryName string
    91  }
    92  
    93  func (_ NoOrganizationTargetedError) Error() string {
    94  	return "No org targeted, use '{{.Command}}' to target an org."
    95  }
    96  
    97  func (e NoOrganizationTargetedError) Translate(translate func(string, ...interface{}) string) string {
    98  	return translate(e.Error(), map[string]interface{}{
    99  		"Command": fmt.Sprintf("%s target -o ORG", e.BinaryName),
   100  	})
   101  }
   102  
   103  type NoSpaceTargetedError struct {
   104  	BinaryName string
   105  }
   106  
   107  func (_ NoSpaceTargetedError) Error() string {
   108  	return "No space targeted, use '{{.Command}}' to target a space."
   109  }
   110  
   111  func (e NoSpaceTargetedError) Translate(translate func(string, ...interface{}) string) string {
   112  	return translate(e.Error(), map[string]interface{}{
   113  		"Command": fmt.Sprintf("%s target -s SPACE", e.BinaryName),
   114  	})
   115  }
   116  
   117  type ApplicationNotFoundError struct {
   118  	Name string
   119  }
   120  
   121  func (_ ApplicationNotFoundError) Error() string {
   122  	return "App {{.AppName}} not found"
   123  }
   124  
   125  func (e ApplicationNotFoundError) Translate(translate func(string, ...interface{}) string) string {
   126  	return translate(e.Error(), map[string]interface{}{
   127  		"AppName": e.Name,
   128  	})
   129  }
   130  
   131  type ServiceInstanceNotFoundError struct {
   132  	Name string
   133  }
   134  
   135  func (_ ServiceInstanceNotFoundError) Error() string {
   136  	return "Service instance {{.ServiceInstance}} not found"
   137  }
   138  
   139  func (e ServiceInstanceNotFoundError) Translate(translate func(string, ...interface{}) string) string {
   140  	return translate(e.Error(), map[string]interface{}{
   141  		"ServiceInstance": e.Name,
   142  	})
   143  }
   144  
   145  type APINotFoundError struct {
   146  	URL string
   147  }
   148  
   149  func (_ APINotFoundError) Error() string {
   150  	return "API endpoint not found at '{{.URL}}'"
   151  }
   152  
   153  func (e APINotFoundError) Translate(translate func(string, ...interface{}) string) string {
   154  	return translate(e.Error(), map[string]interface{}{
   155  		"URL": e.URL,
   156  	})
   157  }
   158  
   159  // ArgumentCombinationError represent an error caused by using two command line
   160  // arguments that cannot be used together.
   161  type ArgumentCombinationError struct {
   162  	Arg1 string
   163  	Arg2 string
   164  }
   165  
   166  func (_ ArgumentCombinationError) Error() string {
   167  	return "Incorrect Usage: '{{.Arg1}}' and '{{.Arg2}}' cannot be used together."
   168  }
   169  
   170  func (e ArgumentCombinationError) Translate(translate func(string, ...interface{}) string) string {
   171  	return translate(e.Error(), map[string]interface{}{
   172  		"Arg1": e.Arg1,
   173  		"Arg2": e.Arg2,
   174  	})
   175  }
   176  
   177  type ParseArgumentError struct {
   178  	ArgumentName string
   179  	ExpectedType string
   180  }
   181  
   182  func (_ ParseArgumentError) Error() string {
   183  	return "Incorrect usage: Value for {{.ArgumentName}} must be {{.ExpectedType}}"
   184  }
   185  
   186  func (e ParseArgumentError) Translate(translate func(string, ...interface{}) string) string {
   187  	return translate(e.Error(), map[string]interface{}{
   188  		"ArgumentName": e.ArgumentName,
   189  		"ExpectedType": e.ExpectedType,
   190  	})
   191  }
   192  
   193  type RequiredArgumentError struct {
   194  	ArgumentName string
   195  }
   196  
   197  func (_ RequiredArgumentError) Error() string {
   198  	return "Incorrect Usage: the required argument `{{.ArgumentName}}` was not provided"
   199  }
   200  
   201  func (e RequiredArgumentError) Translate(translate func(string, ...interface{}) string) string {
   202  	return translate(e.Error(), map[string]interface{}{
   203  		"ArgumentName": e.ArgumentName,
   204  	})
   205  }
   206  
   207  type ThreeRequiredArgumentsError struct {
   208  	ArgumentName1 string
   209  	ArgumentName2 string
   210  	ArgumentName3 string
   211  }
   212  
   213  func (_ ThreeRequiredArgumentsError) Error() string {
   214  	return "Incorrect Usage: the required arguments `{{.ArgumentName1}}`, `{{.ArgumentName2}}`, and `{{.ArgumentName3}}` were not provided"
   215  }
   216  
   217  func (e ThreeRequiredArgumentsError) Translate(translate func(string, ...interface{}) string) string {
   218  	return translate(e.Error(), map[string]interface{}{
   219  		"ArgumentName1": e.ArgumentName1,
   220  		"ArgumentName2": e.ArgumentName2,
   221  		"ArgumentName3": e.ArgumentName3,
   222  	})
   223  }
   224  
   225  type MinimumAPIVersionNotMetError struct {
   226  	CurrentVersion string
   227  	MinimumVersion string
   228  }
   229  
   230  func (_ MinimumAPIVersionNotMetError) Error() string {
   231  	return "This command requires CF API version {{.MinimumVersion}} or higher. Your target is {{.CurrentVersion}}."
   232  }
   233  
   234  func (e MinimumAPIVersionNotMetError) Translate(translate func(string, ...interface{}) string) string {
   235  	return translate(e.Error(), map[string]interface{}{
   236  		"CurrentVersion": e.CurrentVersion,
   237  		"MinimumVersion": e.MinimumVersion,
   238  	})
   239  }
   240  
   241  type LifecycleMinimumAPIVersionNotMetError struct {
   242  	CurrentVersion string
   243  	MinimumVersion string
   244  }
   245  
   246  func (_ LifecycleMinimumAPIVersionNotMetError) Error() string {
   247  	return "Lifecycle value 'staging' requires CF API version {{.MinimumVersion}} or higher. Your target is {{.CurrentVersion}}."
   248  }
   249  
   250  func (e LifecycleMinimumAPIVersionNotMetError) Translate(translate func(string, ...interface{}) string) string {
   251  	return translate(e.Error(), map[string]interface{}{
   252  		"CurrentVersion": e.CurrentVersion,
   253  		"MinimumVersion": e.MinimumVersion,
   254  	})
   255  }
   256  
   257  type HealthCheckTypeUnsupportedError struct {
   258  	SupportedTypes []string
   259  }
   260  
   261  func (_ HealthCheckTypeUnsupportedError) Error() string {
   262  	return "Your target CF API version only supports health check type values {{.SupportedTypes}} and {{.LastSupportedType}}."
   263  }
   264  
   265  func (e HealthCheckTypeUnsupportedError) Translate(translate func(string, ...interface{}) string) string {
   266  	return translate(e.Error(), map[string]interface{}{
   267  		"SupportedTypes":    strings.Join(e.SupportedTypes[:len(e.SupportedTypes)-1], ", "),
   268  		"LastSupportedType": e.SupportedTypes[len(e.SupportedTypes)-1],
   269  	})
   270  }
   271  
   272  type UnsupportedURLSchemeError struct {
   273  	UnsupportedURL string
   274  }
   275  
   276  func (e UnsupportedURLSchemeError) Error() string {
   277  	return "This command does not support the URL scheme in {{.UnsupportedURL}}."
   278  }
   279  
   280  func (e UnsupportedURLSchemeError) Translate(translate func(string, ...interface{}) string) string {
   281  	return translate(e.Error(), map[string]interface{}{
   282  		"UnsupportedURL": e.UnsupportedURL,
   283  	})
   284  }