aboutsummaryrefslogtreecommitdiff
path: root/mobly/snippet/errors.py
blob: 4d41adb162456fd083c3e49c25a3145845c07de9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Copyright 2022 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Module for errors thrown from snippet client objects."""
# TODO(mhaoli): Package `mobly.snippet` should not import errors from
# android_device_lib. However, android_device_lib.DeviceError is the base error
# for the errors thrown from Android snippet clients and device controllers.
# We should resolve this legacy problem.
from mobly.controllers.android_device_lib import errors


class Error(errors.DeviceError):
  """Root error type for snippet clients."""


class ServerRestoreConnectionError(Error):
  """Raised when failed to restore the connection with the snippet server."""


class ServerStartError(Error):
  """Raised when failed to start the snippet server."""


class ServerStartProtocolError(ServerStartError):
  """Raised when protocol reported by the server startup process is unknown."""


class ServerStartPreCheckError(Error):
  """Raised when prechecks for starting the snippet server failed.

  Here are some precheck examples:
  * Whether the required software is installed on the device.
  * Whether the configuration file required by the server startup process
    is available.
  """


class ApiError(Error):
  """Raised when remote API reported an error."""


class ProtocolError(Error):
  """Raised when there was an error in exchanging data with server."""
  NO_RESPONSE_FROM_HANDSHAKE = 'No response from handshake.'
  NO_RESPONSE_FROM_SERVER = ('No response from server. '
                             'Check the device logcat for crashes.')
  MISMATCHED_API_ID = 'RPC request-response ID mismatch.'
  RESPONSE_MISSING_FIELD = 'Missing required field in the RPC response: %s.'


class ServerDiedError(Error):
  """Raised if the snippet server died before all tests finish."""


# Error types for callback handlers
class CallbackHandlerBaseError(errors.DeviceError):
  """Base error type for snippet clients."""


class CallbackHandlerTimeoutError(Error):
  """Raised if the expected event does not occur within the time limit."""