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