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