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 | |
| 35 | class HttpError(DriverError): |
| 36 | """Error related to http requests.""" |
| 37 | |
| 38 | def __init__(self, code, message): |
| 39 | self.code = code |
| 40 | super(HttpError, self).__init__(message) |
| 41 | |
| 42 | @staticmethod |
| 43 | def CreateFromHttpError(http_error): |
| 44 | """Create from an apiclient.errors.HttpError. |
| 45 | |
| 46 | Parse the error code from apiclient.errors.HttpError |
| 47 | and create an instance of HttpError from this module |
| 48 | that has the error code. |
| 49 | |
| 50 | Args: |
| 51 | http_error: An apiclient.errors.HttpError instance. |
| 52 | |
| 53 | Returns: |
| 54 | An HttpError instance from this module. |
| 55 | """ |
| 56 | return HttpError(http_error.resp.status, str(http_error)) |
| 57 | |
| 58 | |
| 59 | class ResourceNotFoundError(HttpError): |
| 60 | """Error raised when a resource is not found.""" |
| 61 | |
| 62 | |
| 63 | class InvalidVirtualDeviceIpError(DriverError): |
| 64 | """Invalid virtual device's IP is set. |
| 65 | |
| 66 | Raise this when the virtual device's IP of an AVD instance is invalid. |
| 67 | """ |
| 68 | |
| 69 | |
| 70 | class HasRetriableRequestsError(DriverError): |
| 71 | """Raised when some retriable requests fail in a batch execution.""" |
| 72 | |
| 73 | |
| 74 | class AuthenticationError(DriverError): |
| 75 | """Raised when authentication fails.""" |
| 76 | |
| 77 | |
| 78 | class DeviceBootError(DriverError): |
| 79 | """To catch device boot errors.""" |
| 80 | |
| 81 | |
| 82 | class NoSubnetwork(DriverError): |
| 83 | """When there is no subnetwork for the GCE.""" |
| 84 | |
| 85 | |
| 86 | class DeviceConnectionError(DriverError): |
| 87 | """To catch device connection errors.""" |
| 88 | |
| 89 | |
| 90 | class DeviceBootTimeoutError(DeviceBootError): |
| 91 | """Raised when an AVD defice failed to boot within timeout.""" |
| 92 | |
Sam Chiu | 81bdc65 | 2018-06-29 18:45:08 +0800 | [diff] [blame] | 93 | |
| 94 | class SetupError(Exception): |
| 95 | """Base Setup cmd exception.""" |
| 96 | |
| 97 | |
Sam Chiu | 7de3b23 | 2018-12-06 19:45:52 +0800 | [diff] [blame] | 98 | class OSTypeError(SetupError): |
| 99 | """Error related to OS type.""" |
| 100 | |
| 101 | |
| 102 | class NoGoogleSDKDetected(SetupError): |
| 103 | """Can't find the SDK path.""" |
| 104 | |
| 105 | |
Sam Chiu | 81bdc65 | 2018-06-29 18:45:08 +0800 | [diff] [blame] | 106 | class PackageInstallError(SetupError): |
| 107 | """Error related to package installation.""" |
| 108 | |
| 109 | |
| 110 | class RequiredPackageNotInstalledError(SetupError): |
| 111 | """Error related to required package not installed.""" |
| 112 | |
| 113 | |
| 114 | class UnableToLocatePkgOnRepositoryError(SetupError): |
| 115 | """Error related to unable to locate package.""" |
| 116 | |
| 117 | |
| 118 | class NotSupportedPlatformError(SetupError): |
| 119 | """Error related to user using a not supported os.""" |
herbertxue | 34776bb | 2018-07-03 21:57:48 +0800 | [diff] [blame] | 120 | |
| 121 | |
| 122 | class ParseBucketRegionError(SetupError): |
| 123 | """Raised when parsing bucket information without region information.""" |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 124 | |
| 125 | |
| 126 | class CreateError(Exception): |
| 127 | """Base Create cmd exception.""" |
| 128 | |
| 129 | |
Kevin Cheng | e258045 | 2018-10-05 16:33:56 -0700 | [diff] [blame] | 130 | class GetAndroidBuildEnvVarError(CreateError): |
| 131 | """Can't get Android Build set environment variables.""" |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 132 | |
| 133 | |
| 134 | class CheckPathError(CreateError): |
| 135 | """Path does not exist.""" |
Kevin Cheng | 3ce4b45 | 2018-08-23 14:47:22 -0700 | [diff] [blame] | 136 | |
| 137 | |
| 138 | class UnsupportedInstanceImageType(CreateError): |
| 139 | """Unsupported create action for given instance/image type.""" |
herbertxue | 79585f4 | 2018-08-28 18:36:45 +0800 | [diff] [blame] | 140 | |
| 141 | |
herbertxue | fd15dfd | 2018-12-04 11:26:27 +0800 | [diff] [blame] | 142 | class UnsupportedFlavor(CreateError): |
| 143 | """Unsupported create action for given flavor name.""" |
| 144 | |
| 145 | |
herbertxue | 79585f4 | 2018-08-28 18:36:45 +0800 | [diff] [blame] | 146 | class GetBuildIDError(CreateError): |
| 147 | """Can't get build id from Android Build.""" |
herbertxue | b617e8a | 2018-08-22 10:02:19 +0800 | [diff] [blame] | 148 | |
| 149 | |
| 150 | class GetBranchFromRepoInfoError(CreateError): |
| 151 | """Can't get branch information from output of #'repo info'.""" |
Sam Chiu | c64f343 | 2018-08-17 11:19:06 +0800 | [diff] [blame] | 152 | |
| 153 | |
| 154 | class NotSupportedHWPropertyError(CreateError): |
| 155 | """An error to wrap a non-supported property issue.""" |
| 156 | |
| 157 | |
| 158 | class MalformedDictStringError(CreateError): |
| 159 | """Error related to unable to convert string to dict.""" |
| 160 | |
| 161 | |
| 162 | class InvalidHWPropertyError(CreateError): |
| 163 | """An error to wrap a malformed hw property issue.""" |
cylan | 1e996c5 | 2018-10-01 16:19:50 +0800 | [diff] [blame] | 164 | |
| 165 | |
| 166 | class GetLocalImageError(CreateError): |
| 167 | """Can't find the local image.""" |
| 168 | |
| 169 | |
| 170 | class GetCvdLocalHostPackageError(CreateError): |
| 171 | """Can't find the lost host package.""" |
chojoyce | cd004bc | 2018-09-13 10:39:00 +0800 | [diff] [blame] | 172 | |
| 173 | |
| 174 | class NoCuttlefishCommonInstalled(SetupError): |
| 175 | """Can't find cuttlefish_common lib.""" |
| 176 | |
| 177 | |
| 178 | class UnpackBootImageError(CreateError): |
| 179 | """Error related to unpack boot.img.""" |
| 180 | |
| 181 | |
| 182 | class BootImgDoesNotExist(CreateError): |
| 183 | """boot.img does not exist.""" |
| 184 | |
| 185 | |
| 186 | class UnsupportedCompressionFileType(SetupError): |
| 187 | """Don't support the compression file type.""" |
Sam Chiu | afbc658 | 2018-09-04 20:47:13 +0800 | [diff] [blame] | 188 | |
| 189 | |
| 190 | class LaunchCVDFail(CreateError): |
| 191 | """Cuttlefish AVD launch failed.""" |
cylan | 6671372 | 2018-10-06 01:38:26 +0800 | [diff] [blame] | 192 | |
| 193 | |
| 194 | class NoExecuteCmd(CreateError): |
| 195 | """Can't find execute bin command.""" |
cylan | 4569dca | 2018-11-02 12:12:53 +0800 | [diff] [blame] | 196 | |
| 197 | |
| 198 | class ReconnectError(Exception): |
| 199 | """Base reconnect cmd exception.""" |
| 200 | |
| 201 | |
| 202 | class NoInstancesFound(ReconnectError): |
| 203 | """No instances found.""" |
chojoyce | efafc02 | 2018-11-08 17:22:16 +0800 | [diff] [blame] | 204 | |
| 205 | |
| 206 | class FunctionTimeoutError(Exception): |
| 207 | """Timeout error of decorator function.""" |