VirtualBox

Ignore:
Timestamp:
Jun 14, 2019 1:00:00 AM (5 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/reporter.py

    r79087 r79138  
    10721072#
    10731073
     1074g_fnComXcptFormatter = None;
     1075
     1076def 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
     1088def 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
    10741118def logXcptWorker(iLevel, fIncErrors, sPrefix="", sText=None, cFrames=1):
    10751119    """
     
    10991143                if sText is not None:
    11001144                    rc = g_oReporter.log(iLevel, "%s%s" % (sPrefix, sText), sCaller, sTsPrf);
    1101                 asInfo = [];
     1145                asInfo = None;
    11021146                try:
    1103                     asInfo = asInfo + traceback.format_exception_only(oType, oValue);
     1147                    asInfo = formatExceptionOnly(oType, oValue, sCaller, sTsPrf);
    11041148                    if cFrames is not None and cFrames <= 1:
    11051149                        asInfo = asInfo + traceback.format_tb(oTraceback, 1);
     
    11331177        g_oLock.release();
    11341178    return rc;
     1179
    11351180
    11361181#
     
    15891634    if oType is not None:
    15901635        sCaller = utils.getCallerName(oTraceback.tb_frame);
    1591         sXcpt   = ' '.join(traceback.format_exception_only(oType, oValue));
     1636        sXcpt   = ' '.join(formatExceptionOnly(oType, oValue, sCaller, utils.getTimePrefix()));
    15921637    else:
    15931638        sCaller = utils.getCallerName();
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