From c9a25d630907e430cef8beab536467b7cc0a6e0d Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 25 Apr 2014 13:55:26 +0200 Subject: [PATCH] Catch configparser exceptions on start --- TODO | 3 --- qutebrowser/app.py | 17 +++++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/TODO b/TODO index f4f467512..1d013a3cb 100644 --- a/TODO +++ b/TODO @@ -6,9 +6,6 @@ Weird font rendering https://bugreports.qt-project.org/browse/QTBUG-20973 https://bugreports.qt-project.org/browse/QTBUG-21036 Changing completion models is awfully slow -new keybinding (not in config) crashes exception handler - Also, what about unknown settings, unknown values, wrong interpolations, - etc.? values written to config are unordered values starting with ; need to be escaped diff --git a/qutebrowser/app.py b/qutebrowser/app.py index e3dedb28b..e3224a2de 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -108,12 +108,17 @@ class QuteBrowser(QApplication): confdir = self._args.confdir try: config.init(confdir) - except config.ValidationError as e: - msgbox = QMessageBox( - QMessageBox.Critical, - "Error while reading config!", - "Error while reading config:\n\n{} -> {}:\n{}".format( - e.section, e.option, e)) + except (config.ValidationError, + configparser.InterpolationError, + configparser.DuplicateSectionError, + configparser.DuplicateOptionError, + configparser.ParsingError) as e: + errstr = "Error while reading config:" + if hasattr(e, 'section') and hasattr(e, 'option'): + errstr += "\n\n{} -> {}:".format(e.section, e.option) + errstr += "\n{}".format(e) + msgbox = QMessageBox(QMessageBox.Critical, + "Error while reading config!", errstr) msgbox.exec_() # We didn't really initialize much so far, so we just quit hard. sys.exit(1)