github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/command/translatableerror/convert_to_translatable_error.go (about) 1 package translatableerror 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "strings" 7 8 "github.com/LukasHeimann/cloudfoundrycli/v8/actor/actionerror" 9 "github.com/LukasHeimann/cloudfoundrycli/v8/api/cloudcontroller/ccerror" 10 "github.com/LukasHeimann/cloudfoundrycli/v8/api/plugin/pluginerror" 11 "github.com/LukasHeimann/cloudfoundrycli/v8/api/uaa" 12 "github.com/LukasHeimann/cloudfoundrycli/v8/util/clissh/ssherror" 13 "github.com/LukasHeimann/cloudfoundrycli/v8/util/download" 14 "github.com/LukasHeimann/cloudfoundrycli/v8/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.EmptyArchiveError: 46 return EmptyDirectoryError(e) 47 case actionerror.EmptyDirectoryError: 48 return EmptyDirectoryError(e) 49 case actionerror.EmptyBuildpackDirectoryError: 50 return EmptyBuildpackDirectoryError(e) 51 case actionerror.FileChangedError: 52 return FileChangedError(e) 53 case actionerror.GettingPluginRepositoryError: 54 return GettingPluginRepositoryError(e) 55 case actionerror.HostnameWithTCPDomainError: 56 return HostnameWithTCPDomainError(e) 57 case actionerror.HTTPHealthCheckInvalidError: 58 return HTTPHealthCheckInvalidError{} 59 case actionerror.InvalidBuildpacksError: 60 return InvalidBuildpacksError{} 61 case actionerror.InvalidHTTPRouteSettings: 62 return PortNotAllowedWithHTTPDomainError(e) 63 case actionerror.InvalidRouteError: 64 return InvalidRouteError(e) 65 case actionerror.InvalidTCPRouteSettings: 66 return HostAndPathNotAllowedWithTCPDomainError(e) 67 case actionerror.IsolationSegmentNotFoundError: 68 return IsolationSegmentNotFoundError(e) 69 case actionerror.MissingNameError: 70 return AppNameOrManifestRequiredError{} 71 case actionerror.MultipleBuildpacksFoundError: 72 return MultipleBuildpacksFoundError(e) 73 case actionerror.NoCompatibleBinaryError: 74 return NoCompatibleBinaryError{} 75 case actionerror.NoDomainsFoundError: 76 return NoDomainsFoundError{} 77 case actionerror.NoHostnameAndSharedDomainError: 78 return NoHostnameAndSharedDomainError{} 79 case actionerror.NoMatchingDomainError: 80 return NoMatchingDomainError(e) 81 case actionerror.NonexistentAppPathError: 82 return FileNotFoundError(e) 83 case actionerror.NoOrganizationTargetedError: 84 return NoOrganizationTargetedError(e) 85 case actionerror.NoSpaceTargetedError: 86 return NoSpaceTargetedError(e) 87 case actionerror.NotLoggedInError: 88 return NotLoggedInError(e) 89 case actionerror.OrganizationNotFoundError: 90 return OrganizationNotFoundError(e) 91 case actionerror.QuotaNotFoundForNameError: 92 return QuotaNotFoundForNameError(e) 93 case actionerror.PasswordGrantTypeLogoutRequiredError: 94 return PasswordGrantTypeLogoutRequiredError(e) 95 case actionerror.PluginCommandsConflictError: 96 return PluginCommandsConflictError(e) 97 case actionerror.PluginInvalidError: 98 return PluginInvalidError(e) 99 case actionerror.PluginNotFoundError: 100 return PluginNotFoundError(e) 101 case actionerror.ProcessInstanceNotFoundError: 102 return ProcessInstanceNotFoundError(e) 103 case actionerror.ProcessInstanceNotRunningError: 104 return ProcessInstanceNotRunningError(e) 105 case actionerror.ProcessNotFoundError: 106 return ProcessNotFoundError(e) 107 case actionerror.PropertyCombinationError: 108 return PropertyCombinationError(e) 109 case actionerror.RepositoryNameTakenError: 110 return RepositoryNameTakenError(e) 111 case actionerror.RepositoryNotRegisteredError: 112 return RepositoryNotRegisteredError(e) 113 case actionerror.RevisionNotFoundError: 114 return RevisionNotFoundError(e) 115 case actionerror.RevisionAmbiguousError: 116 return RevisionAmbiguousError(e) 117 case actionerror.RouteInDifferentSpaceError: 118 return RouteInDifferentSpaceError(e) 119 case actionerror.RoutePathWithTCPDomainError: 120 return RoutePathWithTCPDomainError(e) 121 case actionerror.RouterGroupNotFoundError: 122 return RouterGroupNotFoundError(e) 123 case actionerror.SecurityGroupNotFoundError: 124 return SecurityGroupNotFoundError(e) 125 case actionerror.ServiceInstanceNotFoundError: 126 return ServiceInstanceNotFoundError(e) 127 case actionerror.ServiceInstanceNotShareableError: 128 return ServiceInstanceNotShareableError{ 129 FeatureFlagEnabled: e.FeatureFlagEnabled, 130 ServiceBrokerSharingEnabled: e.ServiceBrokerSharingEnabled, 131 } 132 case actionerror.ServiceInstanceNotSharedToSpaceError: 133 return ServiceInstanceNotSharedToSpaceError{ServiceInstanceName: e.ServiceInstanceName} 134 case actionerror.ServicePlanNotFoundError: 135 return ServicePlanNotFoundError(e) 136 case actionerror.SharedServiceInstanceNotFoundError: 137 return SharedServiceInstanceNotFoundError(e) 138 case actionerror.SpaceNotFoundError: 139 return SpaceNotFoundError{Name: e.Name} 140 case actionerror.StackNotFoundError: 141 return StackNotFoundError(e) 142 case actionerror.StagingFailedError: 143 return StagingFailedError{Message: e.Reason} 144 case actionerror.StagingTimeoutError: 145 return StagingTimeoutError(e) 146 case actionerror.TaskWorkersUnavailableError: 147 return RunTaskError{Message: "Task workers are unavailable."} 148 case actionerror.TCPRouteOptionsNotProvidedError: 149 return TCPRouteOptionsNotProvidedError{} 150 case actionerror.TriggerLegacyPushError: 151 return TriggerLegacyPushError{DomainHostRelated: e.DomainHostRelated} 152 case actionerror.UploadFailedError: 153 return UploadFailedError{Err: ConvertToTranslatableError(e.Err)} 154 case actionerror.CommandLineOptionsAndManifestConflictError: 155 return CommandLineOptionsAndManifestConflictError{ 156 ManifestAttribute: e.ManifestAttribute, 157 CommandLineOptions: e.CommandLineOptions, 158 } 159 160 // Wrapped Errors 161 case TipDecoratorError: 162 e.BaseError = ConvertToTranslatableError(e.BaseError) 163 return e 164 165 // Generic CC Errors 166 case ccerror.APINotFoundError: 167 return APINotFoundError(e) 168 case ccerror.RequestError: 169 return APIRequestError(e) 170 case ccerror.SSLValidationHostnameError: 171 return SSLCertError(e) 172 case ccerror.UnverifiedServerError: 173 return InvalidSSLCertError{URL: e.URL, SuggestedCommand: "api"} 174 175 // Specific CC Errors 176 case ccerror.V2JobFailedError: 177 return JobFailedError(e) 178 case ccerror.V3JobFailedError: 179 return JobFailedError{JobGUID: e.JobGUID, Message: e.Detail} 180 case ccerror.JobTimeoutError: 181 return JobTimeoutError{JobGUID: e.JobGUID} 182 case ccerror.JobFailedNoErrorError: 183 return JobFailedNoErrorError{JobGUID: e.JobGUID} 184 case ccerror.MultiError: 185 return MultiError{Messages: e.Details()} 186 case ccerror.UnprocessableEntityError: 187 if strings.Contains(e.Message, "Task must have a droplet. Specify droplet or assign current droplet to app.") { 188 return RunTaskError{Message: "App is not staged."} 189 } 190 191 // JSON Errors 192 case *json.SyntaxError: 193 return JSONSyntaxError{Err: e} 194 195 // Manifest Errors 196 case manifest.ManifestCreationError: 197 return FileCreationError(e) 198 case manifest.InheritanceFieldError: 199 return TriggerLegacyPushError{InheritanceRelated: true} 200 case manifest.GlobalFieldsError: 201 return TriggerLegacyPushError{GlobalRelated: e.Fields} 202 case manifest.InterpolationError: 203 return InterpolationError(e) 204 205 // Plugin Execution Errors 206 case pluginerror.RawHTTPStatusError: 207 return DownloadPluginHTTPError{Message: e.Status} 208 case pluginerror.SSLValidationHostnameError: 209 return DownloadPluginHTTPError(e) 210 case pluginerror.UnverifiedServerError: 211 return DownloadPluginHTTPError{Message: e.Error()} 212 213 // SSH Errors 214 case ssherror.UnableToAuthenticateError: 215 return SSHUnableToAuthenticateError{} 216 217 // UAA Errors 218 case uaa.UnauthorizedError: 219 return UnauthorizedError(e) 220 case uaa.AccountLockedError: 221 return AccountLockedError(e) 222 case uaa.InsufficientScopeError: 223 return UnauthorizedToPerformActionError{} 224 case uaa.InvalidAuthTokenError: 225 return InvalidRefreshTokenError{} 226 227 // Other Errors 228 case download.RawHTTPStatusError: 229 return HTTPStatusError{Status: e.Status} 230 } 231 232 return err 233 }