Config should be validated with clearer errors

Open
#45 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
backend

Research direction

Start with mautrix/util/config.py, especially _recursive_get, and mautrix_telegram/config.py where bridge.filter.mode is copied during configuration setup. Reproduce the startup failure shown in the report and make invalid nested configuration produce an error that identifies the problem instead of the NoneType traceback.

Written by the indexing model from the issue text.

Description

This doesn't tell me what is wrong:

Feb  3 10:15:20 integrations systemd[1]: Started Telegram Bridge.
Feb  3 10:15:22 integrations python[16389]: Traceback (most recent call last):
Feb  3 10:15:22 integrations python[16389]:   File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
Feb  3 10:15:22 integrations python[16389]:     "__main__", mod_spec)
Feb  3 10:15:22 integrations python[16389]:   File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
Feb  3 10:15:22 integrations python[16389]:     exec(code, run_globals)
Feb  3 10:15:22 integrations python[16389]:   File "/home/telegram/tgenv/lib/python3.6/site-packages/mautrix_telegram/__main__.py", line 113, in <module>
Feb  3 10:15:22 integrations python[16389]:     TelegramBridge().run()
Feb  3 10:15:22 integrations python[16389]:   File "/home/telegram/tgenv/lib/python3.6/site-packages/mautrix/bridge/bridge.py", line 92, in run
Feb  3 10:15:22 integrations python[16389]:     self._prepare()
Feb  3 10:15:22 integrations python[16389]:   File "/home/telegram/tgenv/lib/python3.6/site-packages/mautrix/bridge/bridge.py", line 99, in _prepare
Feb  3 10:15:22 integrations python[16389]:     self.prepare_config(args.config, args.registration, args.base_config)
Feb  3 10:15:22 integrations python[16389]:   File "/home/telegram/tgenv/lib/python3.6/site-packages/mautrix/bridge/bridge.py", line 122, in prepare_config
Feb  3 10:15:22 integrations python[16389]:     self.config.update()
Feb  3 10:15:22 integrations python[16389]:   File "/home/telegram/tgenv/lib/python3.6/site-packages/mautrix/util/config.py", line 152, in update
Feb  3 10:15:22 integrations python[16389]:     self.do_update(ConfigUpdateHelper(base, self))
Feb  3 10:15:22 integrations python[16389]:   File "/home/telegram/tgenv/lib/python3.6/site-packages/mautrix_telegram/config.py", line 146, in do_update
Feb  3 10:15:22 integrations python[16389]:     copy("bridge.filter.mode")
Feb  3 10:15:22 integrations python[16389]:   File "/home/telegram/tgenv/lib/python3.6/site-packages/mautrix/util/config.py", line 112, in copy
Feb  3 10:15:22 integrations python[16389]:     if from_path in self.source:
Feb  3 10:15:22 integrations python[16389]:   File "/home/telegram/tgenv/lib/python3.6/site-packages/mautrix/util/config.py", line 57, in __contains__
Feb  3 10:15:22 integrations python[16389]:     return self.get(key, None) is not None
Feb  3 10:15:22 integrations python[16389]:   File "/home/telegram/tgenv/lib/python3.6/site-packages/mautrix/util/config.py", line 50, in get
Feb  3 10:15:22 integrations python[16389]:     return self._recursive_get(self._data, key, default_value)
Feb  3 10:15:22 integrations python[16389]:   File "/home/telegram/tgenv/lib/python3.6/site-packages/mautrix/util/config.py", line 45, in _recursive_get
Feb  3 10:15:22 integrations python[16389]:     return self._recursive_get(next_data, next_key, default_value)
Feb  3 10:15:22 integrations python[16389]:   File "/home/telegram/tgenv/lib/python3.6/site-packages/mautrix/util/config.py", line 45, in _recursive_get
Feb  3 10:15:22 integrations python[16389]:     return self._recursive_get(next_data, next_key, default_value)
Feb  3 10:15:22 integrations python[16389]:   File "/home/telegram/tgenv/lib/python3.6/site-packages/mautrix/util/config.py", line 46, in _recursive_get
Feb  3 10:15:22 integrations python[16389]:     return data.get(key, default_value)
Feb  3 10:15:22 integrations python[16389]: AttributeError: 'NoneType' object has no attribute 'get'
Feb  3 10:15:22 integrations systemd[1]: telegram.service: Main process exited, code=exited, status=1/FAILURE
Dominant language
Python
Stars
249
Forks
84
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mautrix/python

All issues in mautrix/python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.