diff --git a/qutebrowser/network/qutescheme.py b/qutebrowser/network/qutescheme.py index 9138449c9..c5a5d1118 100644 --- a/qutebrowser/network/qutescheme.py +++ b/qutebrowser/network/qutescheme.py @@ -27,6 +27,8 @@ Module attributes: pyeval_output: The output of the last :pyeval command. """ +import traceback + from PyQt5.QtNetwork import QNetworkReply import qutebrowser @@ -53,22 +55,36 @@ class QuteSchemeHandler(schemehandler.SchemeHandler): Return: A QNetworkReply. """ - path = request.url().path() - # An url like "qute:foo" is split as "scheme:path", not "scheme:host". - logutils.misc.debug("url: {}, path: {}".format( - request.url().toDisplayString(), path)) try: - handler = getattr(QuteHandlers, path) - except AttributeError: - errorstr = "No handler found for {}!".format( - request.url().toDisplayString()) - return schemehandler.ErrorNetworkReply( - request, errorstr, QNetworkReply.ContentNotFoundError, - self.parent()) - else: - data = handler() - return schemehandler.SpecialNetworkReply( - request, data, 'text/html', self.parent()) + path = request.url().path() + # An url like "qute:foo" is split as "scheme:path", not + # "scheme:host". + logutils.misc.debug("url: {}, path: {}".format( + request.url().toDisplayString(), path)) + try: + handler = getattr(QuteHandlers, path) + except AttributeError: + errorstr = "No handler found for {}!".format( + request.url().toDisplayString()) + return schemehandler.ErrorNetworkReply( + request, errorstr, QNetworkReply.ContentNotFoundError, + self.parent()) + else: + data = handler() + return schemehandler.SpecialNetworkReply( + request, data, 'text/html', self.parent()) + except BaseException as e: + # WORKAROUND + # Any exception raised in here will trigger a segfault. + # To prevent this, we return a page with the exception info. + # FIXME: We should report this to PyQt upstream. + text = "Exception in QuteSchemeHandler.createRequest:\n\n" + text += traceback.format_exc() + text += ("\nPlease use :report to report a bug and add the " + "information printed here by hand.") + data = text.encode('utf-8') + return schemehandler.SpecialNetworkReply( + request, data, 'text/plain', self.parent()) class QuteHandlers: