Misleading error for unindented bare values in config file #2621
Labels
Bug
Things to squish; generally used for issues
Needs Triage
Issues that need to be reviewed and categorized
Description
If one manually edits Sopel's config file, it is possible to trigger an error case where the underlying
RawConfigParser
pulls in the value (intended) as if it is a key withNone
as the value.Trying to process the malformed config file into
ConfigSection
s fails, and the end of the resulting traceback misleads the user:ValueError: Missing required value for core.admin_accounts
(core.admin_accounts
is not a required setting)This was discovered by a user who didn't realize that the channel list must be indented, but it can occur anywhere in the config file. Ultimately it's down to any string at the beginning of a line that is not followed by
=
.Reproduction steps
Insert a bare key with no
=
and no value anywhere in Sopel's[core]
section, for example:Expected behavior
I expect one of two behavior options:
ConfigSection.__init__()
when an empty value isNone
instead of''
and re-raises a friendlierConfigurationError
with the malformed string (so the user can easily Ctrl-F for it in their text editor).None
to''
so processing can continue.Option 1 is the strictest, but I wouldn't feel too bad about forcing users who have already manually edited the config file to go back and recheck it for syntax errors. 😁
Option 2 would sort of hide the problem, even though #1973 means Sopel will log a warning (
sopel.bot WARNING - Config option `core.foo` is not defined by its section and may not be recognized by Sopel.
). It's unlikely anyone will look at the logs unless Sopel actually refuses to start.Relevant logs
Notes
I'd like to thank @Duckle29 for prompting me to investigate this. The error was intriguing because it makes absolutely no sense until you tease apart the traceback (and even then, I stopped before figuring out "why admin_accounts specifically?")
Thanks to writing up this issue, I'm now also thinking about a little reorganization of the
Config
class, because why is theConfigSection
class defined inside theConfig
class? (It's been that way since 3.1; the class definition was added 12 years ago.)Sopel version
8.0.0
Installation method
pip install
Python version
3.12.3
Operating system
Ubuntu 22.04.3 LTS
IRCd
No response
Relevant plugins
No response
The text was updated successfully, but these errors were encountered: