Botanism / Botanist

A bot for a healthier experience on discord servers. Provides lots of moderation utilities and improved sharing features!

Home Page:https://discord.gg/mpGM5cg

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make ConfigFile much more reliable.

s0lst1ce opened this issue · comments

Describe the bug
As of now nearly no checks are done on the files being read as config. This is a big issue because sometimes we can end up with empty JSON which cannot be read by the std json library.
Moreover the website expects to always receive JSON files with all possible fields, although some may have placeholder values.

Steps to reproduce
It is unclear how exactly such issues occur. Most often another exception is risen while the file is open. Or parsing to save fails and the file can't be read anymore. Or Updates cause issues with old files.
The exact conditions to be met for the issue to arise is vague.

Expected behavior
Make sure all JSON config files, whatever they configure, always have all fields they should. This should be checked at startup and enforced throughout runtime.

Todo

  • make use of default configuration files for in-place replacements in case of an issue
  • have default files in each different config folder to be used as default
  • have a JSON checker
  • check all files on startup

The JSON checker would be quite heavy. I think that finding out where and why issues sometimes occur with the json module is more efficient.
Still it is impossible to guarantee no errors will be left. For this I have added failsafes that should make sure the JSON files on disk are always sound, at the cost of eventual data losses (although I don't know if they can really be caused). By this I mean that an operation handling a JSON might fail and the ConfigFile handler will discard the changes instead of invalidating the JSON.

I believe jsonschema would be perfect to assert the validity of our JSONs.