diff --git a/modules/config.py b/modules/config.py index 97638a93..5b76f376 100644 --- a/modules/config.py +++ b/modules/config.py @@ -7,7 +7,8 @@ import enum from src import ModuleManager, utils class ConfigInvalidValue(Exception): - pass + def __init__(self, message: str=None): + self.message = message class ConfigSettingInexistent(Exception): pass @@ -113,7 +114,11 @@ class Module(ModuleManager.BaseModule): def _config(self, export_settings, target, setting, value=None): if not value == None: - validated_value = export_settings[setting].parse(value) + try: + validated_value = export_settings[setting].parse(value) + except utils.SettingParseException as e: + raise ConfigInvalidValue(str(e)) + if not validated_value == None: target.set_setting(setting, validated_value) return ConfigResult(ConfigResults.Changed, validated_value) @@ -199,7 +204,10 @@ class Module(ModuleManager.BaseModule): try: result = self._config(export_settings, target, setting, value) - except ConfigInvalidValue: + except ConfigInvalidValue as e: + if not e.message == None: + raise utils.EventError("Invalid value: %s" % e.message) + example = export_settings[setting].get_example() if not example == None: raise utils.EventError("Invalid value. %s" % diff --git a/modules/ircv3_sasl/__init__.py b/modules/ircv3_sasl/__init__.py index 5eb704f7..40f5afc0 100644 --- a/modules/ircv3_sasl/__init__.py +++ b/modules/ircv3_sasl/__init__.py @@ -12,10 +12,17 @@ USERPASS_MECHANISMS = [ "SCRAM-SHA-1", "PLAIN" ] +ALL_MECHANISMS = USERPASS_MECHANISMS+["EXTERNAL"] def _parse(value): mechanism, _, arguments = value.partition(" ") - return {"mechanism": mechanism.upper(), "args": arguments} + mechanism = mechanism.upper() + + if mechanism in ALL_MECHANISMS: + return {"mechanism": mechanism.upper(), "args": arguments} + else: + raise utils.SettingParseException("Unknown SASL mechanism '%s'" + % mechanism) HARDFAIL = utils.BoolSetting("sasl-hard-fail", "Set whether a SASL failure should cause a disconnect") diff --git a/src/utils/__init__.py b/src/utils/__init__.py index 36157204..e9e7bee5 100644 --- a/src/utils/__init__.py +++ b/src/utils/__init__.py @@ -264,6 +264,9 @@ def is_ip(s: str) -> bool: def is_main_thread() -> bool: return threading.current_thread() is threading.main_thread() +class SettingParseException(Exception): + pass + class Setting(object): example: typing.Optional[str] = None def __init__(self, name: str, help: str=None, example: str=None):