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 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 59class ResourceNotFoundError(HttpError): 60 """Error raised when a resource is not found.""" 61 62 63class 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 70class HasRetriableRequestsError(DriverError): 71 """Raised when some retriable requests fail in a batch execution.""" 72 73 74class AuthenticationError(DriverError): 75 """Raised when authentication fails.""" 76 77 78class DeviceBootError(DriverError): 79 """To catch device boot errors.""" 80 81 82class NoSubnetwork(DriverError): 83 """When there is no subnetwork for the GCE.""" 84 85 86class DeviceConnectionError(DriverError): 87 """To catch device connection errors.""" 88 89 90class DeviceBootTimeoutError(DeviceBootError): 91 """Raised when an AVD defice failed to boot within timeout.""" 92 93 94class SetupError(Exception): 95 """Base Setup cmd exception.""" 96 97 98class OSTypeError(SetupError): 99 """Error related to OS type.""" 100 101 102class NoGoogleSDKDetected(SetupError): 103 """Can't find the SDK path.""" 104 105 106class PackageInstallError(SetupError): 107 """Error related to package installation.""" 108 109 110class RequiredPackageNotInstalledError(SetupError): 111 """Error related to required package not installed.""" 112 113 114class UnableToLocatePkgOnRepositoryError(SetupError): 115 """Error related to unable to locate package.""" 116 117 118class NotSupportedPlatformError(SetupError): 119 """Error related to user using a not supported os.""" 120 121 122class ParseBucketRegionError(SetupError): 123 """Raised when parsing bucket information without region information.""" 124 125 126class CreateError(Exception): 127 """Base Create cmd exception.""" 128 129 130class GetAndroidBuildEnvVarError(CreateError): 131 """Can't get Android Build set environment variables.""" 132 133 134class CheckPathError(CreateError): 135 """Path does not exist.""" 136 137 138class UnsupportedInstanceImageType(CreateError): 139 """Unsupported create action for given instance/image type.""" 140 141 142class UnsupportedFlavor(CreateError): 143 """Unsupported create action for given flavor name.""" 144 145 146class GetBuildIDError(CreateError): 147 """Can't get build id from Android Build.""" 148 149 150class GetBranchFromRepoInfoError(CreateError): 151 """Can't get branch information from output of #'repo info'.""" 152 153 154class NotSupportedHWPropertyError(CreateError): 155 """An error to wrap a non-supported property issue.""" 156 157 158class MalformedDictStringError(CreateError): 159 """Error related to unable to convert string to dict.""" 160 161 162class InvalidHWPropertyError(CreateError): 163 """An error to wrap a malformed hw property issue.""" 164 165 166class GetLocalImageError(CreateError): 167 """Can't find the local image.""" 168 169 170class GetCvdLocalHostPackageError(CreateError): 171 """Can't find the lost host package.""" 172 173 174class NoCuttlefishCommonInstalled(SetupError): 175 """Can't find cuttlefish_common lib.""" 176 177 178class UnpackBootImageError(CreateError): 179 """Error related to unpack boot.img.""" 180 181 182class BootImgDoesNotExist(CreateError): 183 """boot.img does not exist.""" 184 185 186class UnsupportedCompressionFileType(SetupError): 187 """Don't support the compression file type.""" 188 189 190class LaunchCVDFail(CreateError): 191 """Cuttlefish AVD launch failed.""" 192 193 194class NoExecuteCmd(CreateError): 195 """Can't find execute bin command.""" 196 197 198class ReconnectError(Exception): 199 """Base reconnect cmd exception.""" 200 201 202class NoInstancesFound(ReconnectError): 203 """No instances found.""" 204 205 206class FunctionTimeoutError(Exception): 207 """Timeout error of decorator function.""" 208 209 210class ZipImageError(Exception): 211 """Zip image error.""" 212