Without lots of passing facts around, robo_print can't add messages to the appropriate facts lists (previously "report"). Also, I don't feel like a print function should be tasked with storing lists of messages for later consumption, or for exiting the program.
SO, here's what I'm going to do:
Add an error_handler function. It will robo_print a message, and then raise a RoboException.
All functions that can potentially call an ERROR will be moved inside of the main try/except/finally; upon catching an ERROR, the message will get added to the local facts object (written immediately), and then sys.exit(1) will get called.
All functions that print a WARNING or REMINDER will instead keep a local list to return at the end of the function. Docstrings and invocation will all be updated to match.
This allows us to greatly compact robo_print.
Finally, I'll refactor the try/except/finally into a robo_runner function, and put all of the error-prone stuff from main in it. All config/args/prefs handling stuff will be orchestrated either by main, or get factored into a setup manager function. This leaves main basically doing just a few lines of work. Thumbs up!
Some of the setup stuff may need its own exception handling written in, since it will be outside of the main recipe generation try/except/finally.
This will ease my OCD over single-responsibility-principle violations!
Without lots of passing facts around, robo_print can't add messages to the appropriate facts lists (previously "report"). Also, I don't feel like a print function should be tasked with storing lists of messages for later consumption, or for exiting the program.
SO, here's what I'm going to do:
Some of the setup stuff may need its own exception handling written in, since it will be outside of the main recipe generation try/except/finally.
This will ease my OCD over single-responsibility-principle violations!