Sam Chiu | 81bdc65 | 2018-06-29 18:45:08 +0800 | [diff] [blame] | 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. |
| 14 | r"""Custom Exceptions for acloud.""" |
| 15 | |
Sam Chiu | 7de3b23 | 2018-12-06 19:45:52 +0800 | [diff] [blame] | 16 | HTTP_NOT_FOUND_CODE = 404 |
| 17 | |
| 18 | |
| 19 | class DriverError(Exception): |
| 20 | """Base Android Gce driver exception.""" |
| 21 | |
| 22 | |
| 23 | class ConfigError(DriverError): |
| 24 | """Error related to config.""" |
| 25 | |
| 26 | |
| 27 | class CommandArgError(DriverError): |
| 28 | """Error related to command line args.""" |
| 29 | |
| 30 | |
| 31 | class GceOperationTimeoutError(DriverError): |
| 32 | """Error raised when a GCE operation timedout.""" |
| 33 | |
| 34 | |
herbertxue | 7a50121 | 2019-08-29 15:37:13 +0800 | [diff] [blame] | 35 | class GetGceZoneError(DriverError): |
| 36 | """Can't get GCE zones info.""" |
| 37 | |
| 38 | |
Sam Chiu | 7de3b23 | 2018-12-06 19:45:52 +0800 | [diff] [blame] | 39 | class HttpError(DriverError): |
| 40 | """Error related to http requests.""" |
| 41 | |
| 42 | def __init__(self, code, message): |
| 43 | self.code = code |
| 44 | super(HttpError, self).__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 | |
| 63 | class ResourceNotFoundError(HttpError): |
| 64 | """Error raised when a resource is not found.""" |
| 65 | |
| 66 | |
| 67 | class 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 | |
| 74 | class HasRetriableRequestsError(DriverError): |
| 75 | """Raised when some retriable requests fail in a batch execution.""" |
| 76 | |
| 77 | |
| 78 | class AuthenticationError(DriverError): |
| 79 | """Raised when authentication fails.""" |
| 80 | |
| 81 | |
| 82 | class DeviceBootError(DriverError): |
| 83 | """To catch device boot errors.""" |
| 84 | |
| 85 | |
| 86 | class NoSubnetwork(DriverError): |
| 87 | """When there is no subnetwork for the GCE.""" |
| 88 | |
| 89 | |
| 90 | class DeviceConnectionError(DriverError): |
| 91 | """To catch device connection errors.""" |
| 92 | |
| 93 | |
herbertxue | 6ef54a5 | 2019-05-02 11:38:58 +0800 | [diff] [blame] | 94 | class PortOccupied(DriverError): |
| 95 | """Raised when open port fail.""" |
| 96 | |
| 97 | |
Sam Chiu | 7de3b23 | 2018-12-06 19:45:52 +0800 | [diff] [blame] | 98 | class DeviceBootTimeoutError(DeviceBootError): |
| 99 | """Raised when an AVD defice failed to boot within timeout.""" |
| 100 | |
Sam Chiu | 81bdc65 | 2018-06-29 18:45:08 +0800 | [diff] [blame] | 101 | |
| 102 | class SetupError(Exception): |
| 103 | """Base Setup cmd exception.""" |
| 104 | |
| 105 | |
Sam Chiu | 7de3b23 | 2018-12-06 19:45:52 +0800 | [diff] [blame] | 106 | class OSTypeError(SetupError): |
| 107 | """Error related to OS type.""" |
| 108 | |
| 109 | |
| 110 | class NoGoogleSDKDetected(SetupError): |
| 111 | """Can't find the SDK path.""" |
| 112 | |
| 113 | |
herbertxue | d69dc51 | 2019-05-30 15:37:15 +0800 | [diff] [blame] | 114 | class NoBillingError(SetupError): |
| 115 | """Billing account isn't enabled.""" |
| 116 | |
| 117 | |
Sam Chiu | 81bdc65 | 2018-06-29 18:45:08 +0800 | [diff] [blame] | 118 | class PackageInstallError(SetupError): |
| 119 | """Error related to package installation.""" |
| 120 | |
| 121 | |
| 122 | class RequiredPackageNotInstalledError(SetupError): |
| 123 | """Error related to required package not installed.""" |
| 124 | |
| 125 | |
| 126 | class UnableToLocatePkgOnRepositoryError(SetupError): |
| 127 | """Error related to unable to locate package.""" |
| 128 | |
| 129 | |
| 130 | class NotSupportedPlatformError(SetupError): |
| 131 | """Error related to user using a not supported os.""" |
herbertxue | 34776bb | 2018-07-03 21:57:48 +0800 | [diff] [blame] | 132 | |
| 133 | |
herbertxue | 36b19b2 | 2020-06-02 17:38:26 +0800 | [diff] [blame] | 134 | class NotSupportedFieldName(SetupError): |
| 135 | """Unsupported field name for user config.""" |
| 136 | |
| 137 | |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 138 | class CreateError(Exception): |
| 139 | """Base Create cmd exception.""" |
| 140 | |
| 141 | |
Kevin Cheng | e258045 | 2018-10-05 16:33:56 -0700 | [diff] [blame] | 142 | class GetAndroidBuildEnvVarError(CreateError): |
| 143 | """Can't get Android Build set environment variables.""" |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 144 | |
| 145 | |
| 146 | class CheckPathError(CreateError): |
| 147 | """Path does not exist.""" |
Kevin Cheng | 3ce4b45 | 2018-08-23 14:47:22 -0700 | [diff] [blame] | 148 | |
| 149 | |
herbertxue | 66c1b95 | 2020-01-01 14:38:06 +0800 | [diff] [blame] | 150 | class CheckGCEZonesQuotaError(CreateError): |
| 151 | """There is no zone have enough quota.""" |
| 152 | |
| 153 | |
Kevin Cheng | 3ce4b45 | 2018-08-23 14:47:22 -0700 | [diff] [blame] | 154 | class UnsupportedInstanceImageType(CreateError): |
| 155 | """Unsupported create action for given instance/image type.""" |
herbertxue | 79585f4 | 2018-08-28 18:36:45 +0800 | [diff] [blame] | 156 | |
| 157 | |
herbertxue | fd15dfd | 2018-12-04 11:26:27 +0800 | [diff] [blame] | 158 | class UnsupportedFlavor(CreateError): |
| 159 | """Unsupported create action for given flavor name.""" |
| 160 | |
| 161 | |
herbertxue | 6ef54a5 | 2019-05-02 11:38:58 +0800 | [diff] [blame] | 162 | class UnsupportedMultiAdbPort(CreateError): |
| 163 | """Unsupported create action for multi AVDs and specify adb port.""" |
| 164 | |
| 165 | |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 166 | class UnsupportedCreateArgs(CreateError): |
| 167 | """Unsupported create arg for a specified AVD type.""" |
| 168 | |
| 169 | |
herbertxue | 79585f4 | 2018-08-28 18:36:45 +0800 | [diff] [blame] | 170 | class GetBuildIDError(CreateError): |
| 171 | """Can't get build id from Android Build.""" |
herbertxue | b617e8a | 2018-08-22 10:02:19 +0800 | [diff] [blame] | 172 | |
| 173 | |
Sam Chiu | c64f343 | 2018-08-17 11:19:06 +0800 | [diff] [blame] | 174 | class NotSupportedHWPropertyError(CreateError): |
| 175 | """An error to wrap a non-supported property issue.""" |
| 176 | |
| 177 | |
| 178 | class MalformedDictStringError(CreateError): |
| 179 | """Error related to unable to convert string to dict.""" |
| 180 | |
| 181 | |
| 182 | class InvalidHWPropertyError(CreateError): |
| 183 | """An error to wrap a malformed hw property issue.""" |
cylan | 1e996c5 | 2018-10-01 16:19:50 +0800 | [diff] [blame] | 184 | |
| 185 | |
| 186 | class GetLocalImageError(CreateError): |
| 187 | """Can't find the local image.""" |
| 188 | |
| 189 | |
| 190 | class GetCvdLocalHostPackageError(CreateError): |
| 191 | """Can't find the lost host package.""" |
chojoyce | cd004bc | 2018-09-13 10:39:00 +0800 | [diff] [blame] | 192 | |
| 193 | |
Hsin-Yi Chen | 7ba4996 | 2019-09-25 18:58:56 +0800 | [diff] [blame] | 194 | class GetSdkRepoPackageError(CreateError): |
| 195 | """Can't find the local SDK repository package for goldfish.""" |
| 196 | |
| 197 | |
chojoyce | cd004bc | 2018-09-13 10:39:00 +0800 | [diff] [blame] | 198 | class NoCuttlefishCommonInstalled(SetupError): |
| 199 | """Can't find cuttlefish_common lib.""" |
| 200 | |
| 201 | |
herbertxue | e5b98ae | 2019-06-19 09:26:17 +0800 | [diff] [blame] | 202 | class ImgDoesNotExist(CreateError): |
| 203 | """Image does not exist.""" |
chojoyce | cd004bc | 2018-09-13 10:39:00 +0800 | [diff] [blame] | 204 | |
| 205 | |
| 206 | class UnsupportedCompressionFileType(SetupError): |
| 207 | """Don't support the compression file type.""" |
Sam Chiu | afbc658 | 2018-09-04 20:47:13 +0800 | [diff] [blame] | 208 | |
| 209 | |
| 210 | class LaunchCVDFail(CreateError): |
| 211 | """Cuttlefish AVD launch failed.""" |
cylan | 6671372 | 2018-10-06 01:38:26 +0800 | [diff] [blame] | 212 | |
| 213 | |
Hsin-Yi Chen | 2a60933 | 2019-10-07 19:39:52 +0800 | [diff] [blame] | 214 | class SubprocessFail(CreateError): |
| 215 | """Subprocess failed.""" |
Hsin-Yi Chen | 7ba4996 | 2019-09-25 18:58:56 +0800 | [diff] [blame] | 216 | |
| 217 | |
cylan | 6671372 | 2018-10-06 01:38:26 +0800 | [diff] [blame] | 218 | class NoExecuteCmd(CreateError): |
| 219 | """Can't find execute bin command.""" |
cylan | 4569dca | 2018-11-02 12:12:53 +0800 | [diff] [blame] | 220 | |
| 221 | |
| 222 | class ReconnectError(Exception): |
| 223 | """Base reconnect cmd exception.""" |
| 224 | |
| 225 | |
| 226 | class NoInstancesFound(ReconnectError): |
| 227 | """No instances found.""" |
chojoyce | efafc02 | 2018-11-08 17:22:16 +0800 | [diff] [blame] | 228 | |
| 229 | |
| 230 | class FunctionTimeoutError(Exception): |
| 231 | """Timeout error of decorator function.""" |
Sam Chiu | 96172ae | 2019-01-31 14:30:30 +0800 | [diff] [blame] | 232 | |
| 233 | |
| 234 | class ZipImageError(Exception): |
| 235 | """Zip image error.""" |
cylan | 694a5d0 | 2019-05-11 19:18:31 +0800 | [diff] [blame] | 236 | |
| 237 | |
| 238 | class UnknownAvdType(Exception): |
herbertxue | 61bfd97 | 2019-09-24 15:51:52 +0800 | [diff] [blame] | 239 | """Unknown AVD type.""" |
| 240 | |
cylan | a49c176 | 2019-09-02 12:14:07 +0800 | [diff] [blame] | 241 | |
| 242 | class UnknownType(Exception): |
herbertxue | 61bfd97 | 2019-09-24 15:51:52 +0800 | [diff] [blame] | 243 | """Unknown type.""" |
Sam Chiu | 5912054 | 2019-08-15 09:32:32 +0800 | [diff] [blame] | 244 | |
| 245 | |
| 246 | class AdbDisconnectFailed(Exception): |
| 247 | """Adb still be alive after disconnect instance.""" |
| 248 | |
| 249 | |
| 250 | class UnsupportedLocalInstanceId(Exception): |
| 251 | """Unsupported local instance id.""" |
Sam Chiu | 34e752e | 2019-08-16 18:15:36 +0800 | [diff] [blame] | 252 | |
| 253 | |
| 254 | class InvalidInstanceDir(Exception): |
| 255 | """Invalid instance dir.""" |