1#!/usr/bin/env python3 2# coding=utf-8 3 4# 5# Copyright (c) 2020-2022 Huawei Device Co., Ltd. 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17# 18 19 20class ParamError(Exception): 21 def __init__(self, error_msg, error_no=""): 22 super(ParamError, self).__init__(error_msg, error_no) 23 self.error_msg = error_msg 24 self.error_no = error_no 25 26 def __str__(self): 27 return str(self.error_msg) 28 29 30class DeviceError(Exception): 31 def __init__(self, error_msg, error_no=""): 32 super(DeviceError, self).__init__(error_msg, error_no) 33 self.error_msg = error_msg 34 self.error_no = error_no 35 36 def __str__(self): 37 return str(self.error_msg) 38 39 40class ExecuteTerminate(Exception): 41 def __init__(self, error_msg="ExecuteTerminate", error_no=""): 42 super(ExecuteTerminate, self).__init__(error_msg, error_no) 43 self.error_msg = error_msg 44 self.error_no = error_no 45 46 def __str__(self): 47 return str(self.error_msg) 48 49 50class ReportException(Exception): 51 """ 52 Exception thrown when a shell command executed on a device takes too long 53 to send its output. 54 """ 55 56 def __init__(self, error_msg="ReportException", error_no=""): 57 super(ReportException, self).__init__(error_msg, error_no) 58 self.error_msg = error_msg 59 self.error_no = error_no 60 61 def __str__(self): 62 return str(self.error_msg) 63 64 65class LiteDeviceError(Exception): 66 def __init__(self, error_msg, error_no=""): 67 super(LiteDeviceError, self).__init__(error_msg, error_no) 68 self.error_msg = error_msg 69 self.error_no = error_no 70 71 def __str__(self): 72 return str(self.error_msg) 73 74 75class HdcError(DeviceError): 76 """ 77 Raised when there is an error in hdc operations. 78 """ 79 80 def __init__(self, error_msg, error_no=""): 81 super(HdcError, self).__init__(error_msg, error_no) 82 self.error_msg = error_msg 83 self.error_no = error_no 84 85 def __str__(self): 86 return str(self.error_msg) 87 88 89class HdcCommandRejectedException(HdcError): 90 """ 91 Exception thrown when hdc refuses a command. 92 """ 93 94 def __init__(self, error_msg, error_no=""): 95 super(HdcCommandRejectedException, self).__init__(error_msg, error_no) 96 self.error_msg = error_msg 97 self.error_no = error_no 98 99 def __str__(self): 100 return str(self.error_msg) 101 102 103class ShellCommandUnresponsiveException(HdcError): 104 """ 105 Exception thrown when a shell command executed on a device takes too long 106 to send its output. 107 """ 108 109 def __init__(self, error_msg="ShellCommandUnresponsiveException", 110 error_no=""): 111 super(ShellCommandUnresponsiveException, self). \ 112 __init__(error_msg, error_no) 113 self.error_msg = error_msg 114 self.error_no = error_no 115 116 def __str__(self): 117 return str(self.error_msg) 118 119 120class DeviceUnresponsiveException(HdcError): 121 """ 122 Exception thrown when a shell command executed on a device takes too long 123 to send its output. 124 """ 125 126 def __init__(self, error_msg="DeviceUnresponsiveException", error_no=""): 127 super(DeviceUnresponsiveException, self).__init__(error_msg, error_no) 128 self.error_msg = error_msg 129 self.error_no = error_no 130 131 def __str__(self): 132 return str(self.error_msg) 133 134 135class AppInstallError(DeviceError): 136 def __init__(self, error_msg, error_no=""): 137 super(AppInstallError, self).__init__(error_msg, error_no) 138 self.error_msg = error_msg 139 self.error_no = error_no 140 141 def __str__(self): 142 return str(self.error_msg) 143 144 145class RpcNotRunningError(DeviceError): 146 def __init__(self, error_msg, error_no=""): 147 super(RpcNotRunningError, self).__init__(error_msg, error_no) 148 self.error_msg = error_msg 149 self.error_no = error_no 150 151 def __str__(self): 152 return str(self.error_msg) 153 154 155class HapNotSupportTest(DeviceError): 156 def __init__(self, error_msg, error_no=""): 157 super(HapNotSupportTest, self).__init__(error_msg, error_no) 158 self.error_msg = error_msg 159 self.error_no = error_no 160 161 def __str__(self): 162 return str(self.error_msg) 163