Display error message when config validation failed
This commit is contained in:
parent
f70fad650d
commit
73dfa30a49
@ -44,7 +44,7 @@ else:
|
||||
import qutebrowser.utils.harfbuzz as harfbuzz
|
||||
harfbuzz.fix()
|
||||
|
||||
from PyQt5.QtWidgets import QApplication, QDialog
|
||||
from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox
|
||||
from PyQt5.QtCore import pyqtSlot, QTimer, QEventLoop
|
||||
|
||||
import qutebrowser
|
||||
@ -61,6 +61,7 @@ from qutebrowser.browser.hints import HintKeyParser
|
||||
from qutebrowser.utils.appdirs import AppDirs
|
||||
from qutebrowser.utils.misc import dotted_getattr
|
||||
from qutebrowser.utils.debug import set_trace # pylint: disable=unused-import
|
||||
from qutebrowser.config.conftypes import ValidationError
|
||||
|
||||
|
||||
class QuteBrowser(QApplication):
|
||||
@ -105,7 +106,17 @@ class QuteBrowser(QApplication):
|
||||
confdir = None
|
||||
else:
|
||||
confdir = self._args.confdir
|
||||
config.init(confdir)
|
||||
try:
|
||||
config.init(confdir)
|
||||
except ValidationError as e:
|
||||
msgbox = QMessageBox(
|
||||
QMessageBox.Critical,
|
||||
"Error while reading config!",
|
||||
"Error while reading config:\n\n{} -> {}:\n{}".format(
|
||||
e.section, e.option, e))
|
||||
msgbox.exec_()
|
||||
# We didn't really initialize much so far, so we just quit hard.
|
||||
sys.exit(1)
|
||||
self.config = config.instance
|
||||
websettings.init()
|
||||
|
||||
|
@ -205,7 +205,12 @@ class Config(QObject):
|
||||
if secname not in cp:
|
||||
continue
|
||||
for k, v in cp[secname].items():
|
||||
self.set('conf', secname, k, v)
|
||||
try:
|
||||
self.set('conf', secname, k, v)
|
||||
except ValidationError as e:
|
||||
e.section = secname
|
||||
e.option = k
|
||||
raise
|
||||
|
||||
def has_option(self, section, option):
|
||||
"""Check if option exists in section.
|
||||
|
@ -22,7 +22,16 @@ from PyQt5.QtGui import QColor
|
||||
|
||||
class ValidationError(ValueError):
|
||||
|
||||
"""Exception raised when a value for a config type was invalid."""
|
||||
"""Exception raised when a value for a config type was invalid.
|
||||
|
||||
Class attributes:
|
||||
section: Section in which the error occured (added when catching and
|
||||
re-raising the exception).
|
||||
option: Option in which the error occured.
|
||||
"""
|
||||
|
||||
section = None
|
||||
option = None
|
||||
|
||||
def __init__(self, value, msg):
|
||||
super().__init__('Invalid value "{}" - {}'.format(value, msg))
|
||||
|
Loading…
Reference in New Issue
Block a user