summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2021-10-25 12:56:07 +0200
committerFlorian Bruhin <me@the-compiler.org>2021-10-25 12:58:52 +0200
commited5af1fcd2b37f12a424e5d5d9b4e57ac331fe2a (patch)
treeed781f25d4c3aa61f4063f1aaf36aaa588664af8
parent7a83b15d6ddfa687462b86611bc2177ff22c670d (diff)
downloadqutebrowser-ed5af1fcd2b37f12a424e5d5d9b4e57ac331fe2a.tar.gz
qutebrowser-ed5af1fcd2b37f12a424e5d5d9b4e57ac331fe2a.zip
Improve error handling with early faulthandler enable
Speculative fix for issue reported by a macOS user: https://crashes.qutebrowser.org/lists?search=NullWriter See https://github.com/pyinstaller/pyinstaller/issues/4481
-rw-r--r--qutebrowser/misc/earlyinit.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/qutebrowser/misc/earlyinit.py b/qutebrowser/misc/earlyinit.py
index c4ff0bb85..1863dedb3 100644
--- a/qutebrowser/misc/earlyinit.py
+++ b/qutebrowser/misc/earlyinit.py
@@ -111,17 +111,21 @@ def init_faulthandler(fileobj=sys.__stderr__):
Args:
fobj: An opened file object to write the traceback to.
"""
- if fileobj is None:
+ try:
+ faulthandler.enable(fileobj)
+ except (RuntimeError, AttributeError) as e:
# When run with pythonw.exe, sys.__stderr__ can be None:
# https://docs.python.org/3/library/sys.html#sys.__stderr__
- # If we'd enable faulthandler in that case, we just get a weird
- # exception, so we don't enable faulthandler if we have no stdout.
+ #
+ # With PyInstaller, it can be a NullWriter raising AttributeError on
+ # fileno: https://github.com/pyinstaller/pyinstaller/issues/4481
#
# Later when we have our data dir available we re-enable faulthandler
# to write to a file so we can display a crash to the user at the next
# start.
+ log.debug(f"Failed to enable early faulthandler: {e}", exc_info=True)
return
- faulthandler.enable(fileobj)
+
if (hasattr(faulthandler, 'register') and hasattr(signal, 'SIGUSR1') and
sys.stderr is not None):
# If available, we also want a traceback on SIGUSR1.