1"""This class is where error information will be stored. 2""" 3 4import json 5 6 7class ActsError(Exception): 8 """Base Acts Error""" 9 def __init__(self, *args, **kwargs): 10 class_name = self.__class__.__name__ 11 self.message = self.__class__.__doc__ 12 self.error_code = getattr(ActsErrorCode, class_name) 13 self.extra = kwargs 14 if len(args) > 0: 15 self.extra['details'] = args 16 17 def json_str(self): 18 """Converts this error to a string in json format. 19 20 Format of the json string is: 21 { 22 "ErrorCode": int 23 "Message": str 24 "Extra": any 25 } 26 27 Returns: 28 A json-format string representing the errors 29 """ 30 d = {} 31 d['ErrorCode'] = self.error_code 32 d['Message'] = self.message 33 d['Extras'] = self.extra 34 json_str = json.dumps(d, indent=4, sort_keys=True) 35 return json_str 36 37 38class ActsErrorCode: 39 # Framework Errors 0-999 40 41 # This error code is used to implement unittests for this class. 42 ActsError = 100 43 AndroidDeviceError = 101 44 45 # Controllers Errors 1000-3999 46 47 Sl4aStartError = 1001 48 Sl4aApiError = 1002 49 Sl4aConnectionError = 1003 50 Sl4aProtocolError = 1004 51 Sl4aNotInstalledError = 1005 52 Sl4aRpcTimeoutError = 1006 53 54 # Util Errors 4000-9999 55 56 FastbootError = 9000 57 AdbError = 9001 58