Changeset 79138 in vbox for trunk/src/VBox/ValidationKit
- Timestamp:
- Jun 14, 2019 1:00:00 AM (6 years ago)
- Location:
- trunk/src/VBox/ValidationKit/testdriver
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/testdriver/reporter.py
r79087 r79138 1072 1072 # 1073 1073 1074 g_fnComXcptFormatter = None; 1075 1076 def setComXcptFormatter(fnCallback): 1077 """ 1078 Install callback for prettier COM exception formatting. 1079 1080 The callback replaces the work done by format_exception_only() and 1081 takes the same arguments. It returns None if not interested in the 1082 exception. 1083 """ 1084 global g_fnComXcptFormatter; 1085 g_fnComXcptFormatter = fnCallback; 1086 return True; 1087 1088 def formatExceptionOnly(oType, oXcpt, sCaller, sTsPrf): 1089 """ 1090 Wrapper around traceback.format_exception_only and __g_fnComXcptFormatter. 1091 """ 1092 #asRet = ['oType=%s type(oXcpt)=%s' % (oType, type(oXcpt),)]; 1093 asRet = []; 1094 1095 # Try the callback first. 1096 fnCallback = g_fnComXcptFormatter; 1097 if fnCallback: 1098 try: 1099 asRetCb = fnCallback(oType, oXcpt); 1100 if asRetCb: 1101 return asRetCb; 1102 #asRet += asRetCb; 1103 except: 1104 g_oReporter.log(0, '** internal-error: Hit exception #2 in __g_fnComXcptFormatter! %s' 1105 % (traceback.format_exc()), sCaller, sTsPrf); 1106 asRet += ['internal error: exception in __g_fnComXcptFormatter']; 1107 1108 # Now try format_exception_only: 1109 try: 1110 asRet += traceback.format_exception_only(oType, oXcpt); 1111 except: 1112 g_oReporter.log(0, '** internal-error: Hit exception #2 in format_exception_only! %s' 1113 % (traceback.format_exc()), sCaller, sTsPrf); 1114 asRet += ['internal error: Exception in format_exception_only!']; 1115 return asRet; 1116 1117 1074 1118 def logXcptWorker(iLevel, fIncErrors, sPrefix="", sText=None, cFrames=1): 1075 1119 """ … … 1099 1143 if sText is not None: 1100 1144 rc = g_oReporter.log(iLevel, "%s%s" % (sPrefix, sText), sCaller, sTsPrf); 1101 asInfo = [];1145 asInfo = None; 1102 1146 try: 1103 asInfo = asInfo + traceback.format_exception_only(oType, oValue);1147 asInfo = formatExceptionOnly(oType, oValue, sCaller, sTsPrf); 1104 1148 if cFrames is not None and cFrames <= 1: 1105 1149 asInfo = asInfo + traceback.format_tb(oTraceback, 1); … … 1133 1177 g_oLock.release(); 1134 1178 return rc; 1179 1135 1180 1136 1181 # … … 1589 1634 if oType is not None: 1590 1635 sCaller = utils.getCallerName(oTraceback.tb_frame); 1591 sXcpt = ' '.join( traceback.format_exception_only(oType, oValue));1636 sXcpt = ' '.join(formatExceptionOnly(oType, oValue, sCaller, utils.getTimePrefix())); 1592 1637 else: 1593 1638 sCaller = utils.getCallerName(); -
trunk/src/VBox/ValidationKit/testdriver/vbox.py
r79092 r79138 182 182 return reporter.error(stringifyErrorInfo(oErrObj)); 183 183 184 def formatComOrXpComException(oType, oXcpt): 185 """ 186 Callback installed with the reporter to better format COM exceptions. 187 Similar to format_exception_only, only it returns None if not interested. 188 """ 189 _ = oType; 190 oVBoxMgr = vboxcon.goHackModuleClass.oVBoxMgr; 191 if oVBoxMgr is None: 192 return None; 193 if not oVBoxMgr.xcptIsOurXcptKind(oXcpt): # pylint: disable=not-callable 194 return None; 195 196 if platform.system() == 'Windows': 197 hrc = oXcpt.hresult; 198 if hrc == ComError.DISP_E_EXCEPTION and oXcpt.excepinfo is not None and len(oXcpt.excepinfo) > 5: 199 hrc = oXcpt.excepinfo[5]; 200 sWhere = oXcpt.excepinfo[1]; 201 sMsg = oXcpt.excepinfo[2]; 202 else: 203 sWhere = None; 204 sMsg = oXcpt.strerror; 205 else: 206 hrc = oXcpt.errno; 207 sWhere = None; 208 sMsg = oXcpt.msg; 209 210 sHrc = oVBoxMgr.xcptToString(hrc); # pylint: disable=not-callable 211 if sHrc.find('(') < 0: 212 sHrc = '%s (%#x)' % (sHrc, hrc & 0xffffffff); 213 214 asRet = ['COM-Xcpt: %s' % (sHrc,)]; 215 if sMsg and sWhere: 216 asRet.append('--------- %s: %s' % (sWhere, sMsg,)); 217 elif sMsg: 218 asRet.append('--------- %s' % (sMsg,)); 219 return asRet; 220 #if sMsg and sWhere: 221 # return ['COM-Xcpt: %s - %s: %s' % (sHrc, sWhere, sMsg,)]; 222 #if sMsg: 223 # return ['COM-Xcpt: %s - %s' % (sHrc, sMsg,)]; 224 #return ['COM-Xcpt: %s' % (sHrc,)]; 184 225 185 226 # … … 1345 1386 vboxcon.goHackModuleClass.oVBoxMgr = self.oVBoxMgr; # VBoxConstantWrappingHack. 1346 1387 vboxcon.fpApiVer = self.fpApiVer; 1388 reporter.setComXcptFormatter(formatComOrXpComException); 1347 1389 1348 1390 except: … … 1432 1474 self.oVBox = None; 1433 1475 vboxcon.goHackModuleClass.oVBoxMgr = None; # VBoxConstantWrappingHack. 1476 reporter.setComXcptFormatter(None); 1434 1477 1435 1478 # Do garbage collection to try get rid of those objects.
Note:
See TracChangeset
for help on using the changeset viewer.