xref: /aosp_15_r20/tools/acloud/errors.py (revision 800a58d989c669b8eb8a71d8df53b1ba3d411444)
1# Copyright 2018 - The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14r"""Custom Exceptions for acloud."""
15
16HTTP_NOT_FOUND_CODE = 404
17
18
19class DriverError(Exception):
20    """Base Android Gce driver exception."""
21
22
23class ConfigError(DriverError):
24    """Error related to config."""
25
26
27class CommandArgError(DriverError):
28    """Error related to command line args."""
29
30
31class GceOperationTimeoutError(DriverError):
32    """Error raised when a GCE operation timedout."""
33
34
35class GetGceZoneError(DriverError):
36    """Can't get GCE zones info."""
37
38
39class HttpError(DriverError):
40    """Error related to http requests."""
41
42    def __init__(self, code, message):
43        self.code = code
44        super().__init__(message)
45
46    @staticmethod
47    def CreateFromHttpError(http_error):
48        """Create from an apiclient.errors.HttpError.
49
50        Parse the error code from apiclient.errors.HttpError
51        and create an instance of HttpError from this module
52        that has the error code.
53
54        Args:
55            http_error: An apiclient.errors.HttpError instance.
56
57        Returns:
58            An HttpError instance from this module.
59        """
60        return HttpError(http_error.resp.status, str(http_error))
61
62
63class ResourceNotFoundError(HttpError):
64    """Error raised when a resource is not found."""
65
66
67class InvalidVirtualDeviceIpError(DriverError):
68    """Invalid virtual device's IP is set.
69
70    Raise this when the virtual device's IP of an AVD instance is invalid.
71    """
72
73
74class HasRetriableRequestsError(DriverError):
75    """Raised when some retriable requests fail in a batch execution."""
76
77
78class AuthenticationError(DriverError):
79    """Raised when authentication fails."""
80
81
82class DeviceBootError(DriverError):
83    """To catch device boot errors."""
84
85
86class DownloadArtifactError(DriverError):
87    """To catch download artifact errors."""
88
89
90class NoSubnetwork(DriverError):
91    """When there is no subnetwork for the GCE."""
92
93
94class DeviceConnectionError(DriverError):
95    """To catch device connection errors."""
96
97
98class PortOccupied(DriverError):
99    """Raised when open port fail."""
100
101
102class DeviceBootTimeoutError(DeviceBootError):
103    """Raised when an AVD defice failed to boot within timeout."""
104
105
106class SetupError(Exception):
107    """Base Setup cmd exception."""
108
109
110class OSTypeError(SetupError):
111    """Error related to OS type."""
112
113
114class NoGoogleSDKDetected(SetupError):
115    """Can't find the SDK path."""
116
117
118class NoBillingError(SetupError):
119    """Billing account isn't enabled."""
120
121
122class PackageInstallError(SetupError):
123    """Error related to package installation."""
124
125
126class RequiredPackageNotInstalledError(SetupError):
127    """Error related to required package not installed."""
128
129
130class UnableToLocatePkgOnRepositoryError(SetupError):
131    """Error related to unable to locate package."""
132
133
134class NotSupportedPlatformError(SetupError):
135    """Error related to user using a not supported os."""
136
137
138class NotSupportedFieldName(SetupError):
139    """Unsupported field name for user config."""
140
141
142class CreateError(Exception):
143    """Base Create cmd exception."""
144
145
146class GetAndroidBuildEnvVarError(CreateError):
147    """Can't get Android Build set environment variables."""
148
149
150class CheckPathError(CreateError):
151    """Path does not exist."""
152
153
154class CheckGCEZonesQuotaError(CreateError):
155    """There is no zone have enough quota."""
156
157
158class UnsupportedInstanceImageType(CreateError):
159    """Unsupported create action for given instance/image type."""
160
161
162class UnsupportedFlavor(CreateError):
163    """Unsupported create action for given flavor name."""
164
165
166class UnsupportedMultiAdbPort(CreateError):
167    """Unsupported create action for multi AVDs and specify adb port."""
168
169
170class UnsupportedCreateArgs(CreateError):
171    """Unsupported create arg for a specified AVD type."""
172
173
174class GetBuildIDError(CreateError):
175    """Can't get build id from Android Build."""
176
177
178class NotSupportedHWPropertyError(CreateError):
179    """An error to wrap a non-supported property issue."""
180
181
182class MalformedDictStringError(CreateError):
183    """Error related to unable to convert string to dict."""
184
185
186class InvalidHWPropertyError(CreateError):
187    """An error to wrap a malformed hw property issue."""
188
189
190class GetLocalImageError(CreateError):
191    """Can't find the local image."""
192
193
194class GetRemoteImageError(CreateError):
195    """An error to download the remote image."""
196
197
198class GetCvdLocalHostPackageError(CreateError):
199    """Can't find the lost host package."""
200
201
202class GetTrustyLocalHostPackageError(CreateError):
203    """Can't find the trusty host package."""
204
205
206class GetSdkRepoPackageError(CreateError):
207    """Can't find the local SDK repository package for goldfish."""
208
209
210class NoCuttlefishCommonInstalled(SetupError):
211    """Can't find cuttlefish_common lib."""
212
213
214class ImgDoesNotExist(CreateError):
215    """Image does not exist."""
216
217
218class UnsupportedCompressionFileType(SetupError):
219    """Don't support the compression file type."""
220
221
222class LaunchCVDFail(CreateError):
223    """Cuttlefish AVD launch failed."""
224
225
226class SshConnectFail(CreateError):
227    """Ssh connect to GCE instance failed."""
228
229
230class SubprocessFail(CreateError):
231    """Subprocess failed."""
232
233
234class NoExecuteCmd(CreateError):
235    """Can't find execute bin command."""
236
237
238class ReconnectError(Exception):
239    """Base reconnect cmd exception."""
240
241
242class NoInstancesFound(ReconnectError):
243    """No instances found."""
244
245
246class FunctionTimeoutError(Exception):
247    """Timeout error of decorator function."""
248
249
250class ZipImageError(Exception):
251    """Zip image error."""
252
253
254class UnknownAvdType(Exception):
255    """Unknown AVD type."""
256
257
258class UnknownType(Exception):
259    """Unknown type."""
260
261
262class AdbDisconnectFailed(Exception):
263    """Adb still be alive after disconnect instance."""
264
265
266class UnsupportedLocalInstanceId(Exception):
267    """Unsupported local instance id."""
268
269
270class InvalidInstanceDir(Exception):
271    """Invalid instance dir."""
272