VirtualBox

Ignore:
Timestamp:
Jun 14, 2019 1:00:00 AM (6 years ago)
Author:
vboxsync
Message:

ValKit: Hack to try make COM and XPCOM exceptions more readable.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/testdriver/vbox.py

    r79092 r79138  
    182182    return reporter.error(stringifyErrorInfo(oErrObj));
    183183
     184def 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,)];
    184225
    185226#
     
    13451386            vboxcon.goHackModuleClass.oVBoxMgr  = self.oVBoxMgr; # VBoxConstantWrappingHack.
    13461387            vboxcon.fpApiVer                    = self.fpApiVer;
     1388            reporter.setComXcptFormatter(formatComOrXpComException);
    13471389
    13481390        except:
     
    14321474        self.oVBox            = None;
    14331475        vboxcon.goHackModuleClass.oVBoxMgr = None; # VBoxConstantWrappingHack.
     1476        reporter.setComXcptFormatter(None);
    14341477
    14351478        # Do garbage collection to try get rid of those objects.
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette