billmania / roboquest_ui

The front-end logic for the RoboQuest project
0 stars 1 forks source link

Verify integrity of configuration.json before saving #136

Closed billmania closed 1 month ago

billmania commented 11 months ago

Reconfiguring allows the user to change the label on a widget, but this causes the configuration object to lose its "id" property.

Before writing the configuration.json file to the persistent storage, check a few things:

  1. can file be parsed
  2. does each widget have an id
  3. is type in button, indicator, value, slider, joystick, gamepad
  4. is each id unique
  5. does each widget have a label
  6. is each label unique
  7. replace label SPACEs with UNDERSCORE
  8. remove QUOTATION, APOSTROPHE, PERIOD, DASH characters
  9. if upValues is empty, remove it
  10. if key downValues and upValues are both empty, remove the key
  11. if keys is empty remove it
billmania commented 4 months ago

There are two separate scenarios to cover.

Writing a corrupted file This one must be detected at run-time by enhancing the ConfigFile.save_config() method.

Corruption of the file after writing This could be caused by any of improper halting of the RaspPi and failure of the microSD. This scenario is best detected by the updater.py script, before the docker containers are started.

billmania commented 2 months ago

updater.py doesn't use the configuration.json, but ensures a parseable version is in place

  1. if doesn't have the "version" attribute, or isn't parseable, the .old is restored
  2. if the file is empty or doesn't exist, the .old is restored

rq_core doesn't need configuration.json to start

**rq_ui does require the configuration.json

  1. if the file is not present, a small, default version will be installed
  2. if the file is empty, rq_ui will not start
  3. if the file doesn't parse, rq_ui will not start
  4. if a widget is missing a config parameter, rq_ui wouldn't start, but that lack of robustness has been corrected