lundybernard / batconf

Application configuration tool from the BAT project
MIT License
2 stars 0 forks source link

missing config file causes exception #1

Closed lundybernard closed 2 years ago

lundybernard commented 3 years ago

When a FileConfig source is included in the Configuration source_list, but a file is not provided by the user, or found during FileConfig.init, looking up an attribute throws the following error.

  File "/venv/lib/python3.9/site-packages/batconf/manager.py", line 42, in __getattr__
    return self._get_config_opt(name, self._mod_)
  File "/venv/lib/python3.9/site-packages/batconf/manager.py", line 45, in _get_config_opt
    if value := self._config_sources.get(key, path=path):
  File "/venv/lib/python3.9/site-packages/batconf/source.py", line 17, in get
    if value := source.get(key, path):
  File "/venv/lib/python3.9/site-packages/batconf/sources/file.py", line 38, in get
    if not (conf := conf.get(k)):
AttributeError: 'str' object has no attribute 'get'

FIX: missing keys in the config file should return None, not raise an AttributeError. If the file is missing all FileConfig.get should always return None

lundybernard commented 2 years ago

This is improved in v1.3, It now raises a warning about the missing config file, and the application runs successfully.

However, if the config file is missing, and the config value is not found in any source, It will raise the same AttributeError: 'str' object has no attribute 'get' Exception, instead of the helpful missing-value message which tells you what value is missing, ex: please add PROJECT_CONFIG_ITEM to ENV etc.

missing config items should raise the helpful missing value message even if a config file is not specified.