Make log.stub work when inspect.stack fails
I got this during shutdown once: Traceback (most recent call last): File ".../qutebrowser/mainwindow/mainwindow.py", line 552, in closeEvent File ".../qutebrowser/mainwindow/mainwindow.py", line 538, in _do_close File ".../qutebrowser/mainwindow/tabbedbrowser.py", line 218, in shutdown self._remove_tab(tab) File ".../qutebrowser/mainwindow/tabbedbrowser.py", line 280, in _remove_tab tab.shutdown() File ".../qutebrowser/browser/webengine/webenginetab.py", line 536, in shutdown log.stub() File ".../qutebrowser/utils/log.py", line 151, in stub function = inspect.stack()[1][3] File "/usr/lib64/python3.5/inspect.py", line 1464, in stack return getouterframes(sys._getframe(1), context) File "/usr/lib64/python3.5/inspect.py", line 1441, in getouterframes frameinfo = (frame,) + getframeinfo(frame, context) File "/usr/lib64/python3.5/inspect.py", line 1414, in getframeinfo lines, lnum = findsource(frame) File "/usr/lib64/python3.5/inspect.py", line 804, in findsource if pat.match(lines[lnum]): break IndexError: list index out of range
This commit is contained in:
parent
53ef16e26b
commit
378976db29
@ -148,7 +148,11 @@ console_filter = None
|
||||
|
||||
def stub(suffix=''):
|
||||
"""Show a STUB: message for the calling function."""
|
||||
function = inspect.stack()[1][3]
|
||||
try:
|
||||
function = inspect.stack()[1][3]
|
||||
except IndexError: # pragma: no cover
|
||||
misc.exception("Failed to get stack")
|
||||
function = '<unknown>'
|
||||
text = "STUB: {}".format(function)
|
||||
if suffix:
|
||||
text = '{} ({})'.format(text, suffix)
|
||||
|
Loading…
Reference in New Issue
Block a user