blob: 0f4c6449c4556a102bae06f16aa293711eba7344 [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.
16
17"""Define errors that are raised by the driver."""
18
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070019HTTP_NOT_FOUND_CODE = 404
20
21
22class DriverError(Exception):
23 """Base Android Gce driver exception."""
24
25
26class ConfigError(DriverError):
27 """Error related to config."""
28
29
30class CommandArgError(DriverError):
31 """Error related to command line args."""
32
33
34class GceOperationTimeoutError(DriverError):
35 """Error raised when a GCE operation timedout."""
36
37
38class HttpError(DriverError):
39 """Error related to http requests."""
40
41 def __init__(self, code, message):
42 self.code = code
43 super(HttpError, self).__init__(message)
44
45 @staticmethod
46 def CreateFromHttpError(http_error):
47 """Create from an apiclient.errors.HttpError.
48
49 Parse the error code from apiclient.errors.HttpError
50 and create an instance of HttpError from this module
51 that has the error code.
52
53 Args:
54 http_error: An apiclient.errors.HttpError instance.
55
56 Returns:
57 An HttpError instance from this module.
58 """
59 return HttpError(http_error.resp.status, str(http_error))
60
61
62class ResourceNotFoundError(HttpError):
63 """Error raised when a resource is not found."""
64
65
66class InvalidVirtualDeviceIpError(DriverError):
67 """Invalid virtual device's IP is set.
68
69 Raise this when the virtual device's IP of an AVD instance is invalid.
70 """
71
72
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070073class HasRetriableRequestsError(DriverError):
74 """Raised when some retriable requests fail in a batch execution."""
75
76
77class AuthentcationError(DriverError):
78 """Raised when authentication fails."""
Kevin Chengb5963882018-05-09 00:06:27 -070079
80
81class DeviceBootError(DriverError):
82 """To catch device boot errors."""
83
84
85class DeviceBootTimeoutError(DeviceBootError):
86 """Raised when an AVD defice failed to boot within timeout."""