homebysix / recipe-robot

A kick ass tool for creating AutoPkg recipes.
Apache License 2.0
301 stars 28 forks source link

robo_print handling of ERROR, WARNING, REMINDER #55

Closed sheagcraig closed 8 years ago

sheagcraig commented 8 years ago

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:

  1. Add an error_handler function. It will robo_print a message, and then raise a RoboException.
  2. 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.
  3. 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.
  4. This allows us to greatly compact robo_print.
  5. 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!

homebysix commented 8 years ago

This all sounds great to me.

sheagcraig commented 8 years ago

I think we did this already, no?