From f8779e10eeb86b6c9bb393b8df3eee382110e2b7 Mon Sep 17 00:00:00 2001 From: Humorous Baby Date: Fri, 12 Apr 2019 09:51:51 -0400 Subject: [PATCH] admin: prevent `unset`'ing required settings Any setting with `default = NO_DEFAULT` cannot be unset; e.g., `core.owner` --- sopel/config/types.py | 2 ++ sopel/modules/admin.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/sopel/config/types.py b/sopel/config/types.py index 05ae7d895e..1d87915e18 100644 --- a/sopel/config/types.py +++ b/sopel/config/types.py @@ -156,6 +156,8 @@ def __get__(self, instance, owner=None): def __set__(self, instance, value): if value is None: + if self.default == NO_DEFAULT: + raise ValueError('Cannot unset an option with a required value.') instance._parser.remove_option(instance._section_name, self.name) return value = self.serialize(value) diff --git a/sopel/modules/admin.py b/sopel/modules/admin.py index fadf0f36d7..f79467f3c8 100644 --- a/sopel/modules/admin.py +++ b/sopel/modules/admin.py @@ -369,7 +369,10 @@ def unset_config(bot, trigger): bot.reply('Invalid command; no value should be provided to unset.') return - setattr(section, option, None) + try: + setattr(section, option, None) + except ValueError: + bot.reply('Cannot unset {}.{}; it is a required option.'.format(section_name, option)) @sopel.module.require_privmsg