From 378976db299fe46d02beb79f0cae45e5e8d30379 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 6 Oct 2016 21:02:44 +0200 Subject: [PATCH] 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 --- qutebrowser/utils/log.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/qutebrowser/utils/log.py b/qutebrowser/utils/log.py index c88df8a38..044b75b65 100644 --- a/qutebrowser/utils/log.py +++ b/qutebrowser/utils/log.py @@ -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 = '' text = "STUB: {}".format(function) if suffix: text = '{} ({})'.format(text, suffix)