blob: 3091422059cd9c91bbaa3db97764efefdad5f1a6 [file] [log] [blame]
Keun Soo Yimb293fdb2016-09-21 16:03:44 -07001#!/usr/bin/env python
2#
3# Copyright 2016 - The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070016"""Define errors that are raised by the driver."""
17
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070018HTTP_NOT_FOUND_CODE = 404
19
20
21class DriverError(Exception):
22 """Base Android Gce driver exception."""
23
24
25class ConfigError(DriverError):
26 """Error related to config."""
27
28
29class CommandArgError(DriverError):
30 """Error related to command line args."""
31
32
33class GceOperationTimeoutError(DriverError):
34 """Error raised when a GCE operation timedout."""
35
36
37class HttpError(DriverError):
38 """Error related to http requests."""
39
40 def __init__(self, code, message):
41 self.code = code
42 super(HttpError, self).__init__(message)
43
44 @staticmethod
45 def CreateFromHttpError(http_error):
46 """Create from an apiclient.errors.HttpError.
47
48 Parse the error code from apiclient.errors.HttpError
49 and create an instance of HttpError from this module
50 that has the error code.
51
52 Args:
53 http_error: An apiclient.errors.HttpError instance.
54
55 Returns:
56 An HttpError instance from this module.
57 """
58 return HttpError(http_error.resp.status, str(http_error))
59
60
61class ResourceNotFoundError(HttpError):
62 """Error raised when a resource is not found."""
63
64
65class InvalidVirtualDeviceIpError(DriverError):
66 """Invalid virtual device's IP is set.
67
68 Raise this when the virtual device's IP of an AVD instance is invalid.
69 """
70
71
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070072class HasRetriableRequestsError(DriverError):
73 """Raised when some retriable requests fail in a batch execution."""
74
75
xingdai147a9782018-08-01 17:13:51 -070076class AuthenticationError(DriverError):
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070077 """Raised when authentication fails."""
Kevin Chengb5963882018-05-09 00:06:27 -070078
79
80class DeviceBootError(DriverError):
herbertxue769e1b72018-05-17 08:27:48 +000081 """To catch device boot errors."""
Kevin Chengb5963882018-05-09 00:06:27 -070082
83
84class DeviceBootTimeoutError(DeviceBootError):
herbertxue769e1b72018-05-17 08:27:48 +000085 """Raised when an AVD defice failed to boot within timeout."""