github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/command/translatableerror/convert_to_translatable_error.go (about) 1 package translatableerror 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "strings" 7 8 "code.cloudfoundry.org/cli/actor/actionerror" 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 10 "code.cloudfoundry.org/cli/api/plugin/pluginerror" 11 "code.cloudfoundry.org/cli/api/uaa" 12 "code.cloudfoundry.org/cli/util/clissh/ssherror" 13 "code.cloudfoundry.org/cli/util/manifest" 14 log "github.com/sirupsen/logrus" 15 ) 16 17 func ConvertToTranslatableError(err error) error { 18 log.WithField("err", fmt.Sprintf("%#v", err)).Debugf("convert to translatable error") 19 20 switch e := err.(type) { 21 // Action Errors 22 case actionerror.AddPluginRepositoryError: 23 return AddPluginRepositoryError(e) 24 case actionerror.ApplicationNotFoundError: 25 return ApplicationNotFoundError(e) 26 case actionerror.ApplicationNotStartedError: 27 return ApplicationNotStartedError(e) 28 case actionerror.AppNotFoundInManifestError: 29 return AppNotFoundInManifestError(e) 30 case actionerror.AssignDropletError: 31 return AssignDropletError(e) 32 case actionerror.CommandLineOptionsWithMultipleAppsError: 33 return CommandLineArgsWithMultipleAppsError{} 34 case actionerror.DockerPasswordNotSetError: 35 return DockerPasswordNotSetError{} 36 case actionerror.DomainNotFoundError: 37 return DomainNotFoundError(e) 38 case manifest.EmptyBuildpacksError: 39 return EmptyBuildpacksError(e) 40 case actionerror.EmptyDirectoryError: 41 return EmptyDirectoryError(e) 42 case actionerror.FileChangedError: 43 return FileChangedError(e) 44 case actionerror.GettingPluginRepositoryError: 45 return GettingPluginRepositoryError(e) 46 case actionerror.HostnameWithTCPDomainError: 47 return HostnameWithTCPDomainError(e) 48 case actionerror.HTTPHealthCheckInvalidError: 49 return HTTPHealthCheckInvalidError{} 50 case actionerror.InvalidBuildpacksError: 51 return InvalidBuildpacksError{} 52 case actionerror.InvalidHTTPRouteSettings: 53 return PortNotAllowedWithHTTPDomainError(e) 54 case actionerror.InvalidRouteError: 55 return InvalidRouteError(e) 56 case actionerror.InvalidTCPRouteSettings: 57 return HostAndPathNotAllowedWithTCPDomainError(e) 58 case actionerror.IsolationSegmentNotFoundError: 59 return IsolationSegmentNotFoundError(e) 60 case actionerror.MissingNameError: 61 return RequiredNameForPushError{} 62 case actionerror.NoCompatibleBinaryError: 63 return NoCompatibleBinaryError{} 64 case actionerror.NoDomainsFoundError: 65 return NoDomainsFoundError{} 66 case actionerror.NoHostnameAndSharedDomainError: 67 return NoHostnameAndSharedDomainError{} 68 case actionerror.NoMatchingDomainError: 69 return NoMatchingDomainError(e) 70 case actionerror.NonexistentAppPathError: 71 return FileNotFoundError(e) 72 case actionerror.NoOrganizationTargetedError: 73 return NoOrganizationTargetedError(e) 74 case actionerror.NoSpaceTargetedError: 75 return NoSpaceTargetedError(e) 76 case actionerror.NotLoggedInError: 77 return NotLoggedInError(e) 78 case actionerror.OrganizationNotFoundError: 79 return OrganizationNotFoundError(e) 80 case actionerror.PasswordGrantTypeLogoutRequiredError: 81 return PasswordGrantTypeLogoutRequiredError(e) 82 case actionerror.PluginCommandsConflictError: 83 return PluginCommandsConflictError(e) 84 case actionerror.PluginInvalidError: 85 return PluginInvalidError(e) 86 case actionerror.PluginNotFoundError: 87 return PluginNotFoundError(e) 88 case actionerror.ProcessInstanceNotFoundError: 89 return ProcessInstanceNotFoundError(e) 90 case actionerror.ProcessInstanceNotRunningError: 91 return ProcessInstanceNotRunningError(e) 92 case actionerror.ProcessNotFoundError: 93 return ProcessNotFoundError(e) 94 case actionerror.PropertyCombinationError: 95 return PropertyCombinationError(e) 96 case actionerror.RepositoryNameTakenError: 97 return RepositoryNameTakenError(e) 98 case actionerror.RepositoryNotRegisteredError: 99 return RepositoryNotRegisteredError(e) 100 case actionerror.RouteInDifferentSpaceError: 101 return RouteInDifferentSpaceError(e) 102 case actionerror.RoutePathWithTCPDomainError: 103 return RoutePathWithTCPDomainError(e) 104 case actionerror.SecurityGroupNotFoundError: 105 return SecurityGroupNotFoundError(e) 106 case actionerror.ServiceInstanceNotFoundError: 107 return ServiceInstanceNotFoundError(e) 108 case actionerror.ServiceInstanceNotShareableError: 109 return ServiceInstanceNotShareableError{ 110 FeatureFlagEnabled: e.FeatureFlagEnabled, 111 ServiceBrokerSharingEnabled: e.ServiceBrokerSharingEnabled, 112 } 113 case actionerror.ServiceInstanceNotSharedToSpaceError: 114 return ServiceInstanceNotSharedToSpaceError{ServiceInstanceName: e.ServiceInstanceName} 115 case actionerror.SharedServiceInstanceNotFoundError: 116 return SharedServiceInstanceNotFoundError(e) 117 case actionerror.SpaceNotFoundError: 118 return SpaceNotFoundError{Name: e.Name} 119 case actionerror.StackNotFoundError: 120 return StackNotFoundError(e) 121 case actionerror.StagingTimeoutError: 122 return StagingTimeoutError(e) 123 case actionerror.TaskWorkersUnavailableError: 124 return RunTaskError{Message: "Task workers are unavailable."} 125 case actionerror.TCPRouteOptionsNotProvidedError: 126 return TCPRouteOptionsNotProvidedError{} 127 case actionerror.TriggerLegacyPushError: 128 return TriggerLegacyPushError{DomainHostRelated: e.DomainHostRelated} 129 case actionerror.UploadFailedError: 130 return UploadFailedError{Err: ConvertToTranslatableError(e.Err)} 131 case actionerror.CommandLineOptionsAndManifestConflictError: 132 return CommandLineOptionsAndManifestConflictError{ 133 ManifestAttribute: e.ManifestAttribute, 134 CommandLineOptions: e.CommandLineOptions, 135 } 136 137 // Generic CC Errors 138 case ccerror.APINotFoundError: 139 return APINotFoundError(e) 140 case ccerror.RequestError: 141 return APIRequestError(e) 142 case ccerror.SSLValidationHostnameError: 143 return SSLCertError(e) 144 case ccerror.UnverifiedServerError: 145 return InvalidSSLCertError(e) 146 147 // Specific CC Errors 148 case ccerror.JobFailedError: 149 return JobFailedError(e) 150 case ccerror.JobTimeoutError: 151 return JobTimeoutError{JobGUID: e.JobGUID} 152 case ccerror.MultiError: 153 return MultiError{Messages: e.Details()} 154 case ccerror.UnprocessableEntityError: 155 if strings.Contains(e.Message, "Task must have a droplet. Specify droplet or assign current droplet to app.") { 156 return RunTaskError{Message: "App is not staged."} 157 } 158 159 // JSON Errors 160 case *json.SyntaxError: 161 return JSONSyntaxError{Err: e} 162 163 // Manifest Errors 164 case manifest.ManifestCreationError: 165 return ManifestCreationError(e) 166 case manifest.InheritanceFieldError: 167 return TriggerLegacyPushError{InheritanceRelated: true} 168 case manifest.GlobalFieldsError: 169 return TriggerLegacyPushError{GlobalRelated: e.Fields} 170 case manifest.InterpolationError: 171 return InterpolationError(e) 172 173 // Plugin Execution Errors 174 case pluginerror.RawHTTPStatusError: 175 return DownloadPluginHTTPError{Message: e.Status} 176 case pluginerror.SSLValidationHostnameError: 177 return DownloadPluginHTTPError(e) 178 case pluginerror.UnverifiedServerError: 179 return DownloadPluginHTTPError{Message: e.Error()} 180 181 // SSH Errors 182 case ssherror.UnableToAuthenticateError: 183 return SSHUnableToAuthenticateError{} 184 185 // UAA Errors 186 case uaa.BadCredentialsError: 187 return BadCredentialsError{} 188 case uaa.InsufficientScopeError: 189 return UnauthorizedToPerformActionError{} 190 case uaa.InvalidAuthTokenError: 191 return InvalidRefreshTokenError{} 192 } 193 194 return err 195 }