diff --git a/qutebrowser/config/configexc.py b/qutebrowser/config/configexc.py new file mode 100644 index 000000000..5a05b85b3 --- /dev/null +++ b/qutebrowser/config/configexc.py @@ -0,0 +1,77 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2014 Florian Bruhin (The Compiler) +# +# This file is part of qutebrowser. +# +# qutebrowser is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# qutebrowser is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with qutebrowser. If not, see . + +"""Exceptions related to config parsing.""" + + +class Error(Exception): + + """Base exception for config-related errors.""" + + pass + + +class ValidationError(Error): + + """Raised when a value for a config type was invalid. + + Attributes: + section: Section in which the error occured (added when catching and + re-raising the exception). + option: Option in which the error occured. + """ + + def __init__(self, value, msg): + super().__init__("Invalid value '{}' - {}".format(value, msg)) + self.section = None + self.option = None + + +class NoSectionError(Error): + + """Raised when no section matches a requested option.""" + + def __init__(self, section): + super().__init__("Section {!r} does not exist!".format(section)) + self.section = section + + +class NoOptionError(Error): + + """Raised when an option was not found.""" + + def __init__(self, option, section): + super().__init__("No option {!r} in section: {!r}".format( + option, section)) + self.option = option + self.section = section + + +class InterpolationSyntaxError(Error): + + """Raised when the source text contains invalid syntax. + + Current implementation raises this exception when the source text into + which substitutions are made does not conform to the required syntax. + """ + + def __init__(self, option, section, msg): + super().__init__(msg) + self.option = option + self.section = section