energyPATHWAYS / EnergyPATHWAYS

EnergyPATHWAYS model is a professional, open-source energy and carbon planning tool for use in evaluating long-term, economy-wide greenhouse gas mitigation scenarios.
MIT License
45 stars 15 forks source link

Tighten up use of "try:" #18

Open mactyr opened 8 years ago

mactyr commented 8 years ago

As a Pathways developer-user I want the scope of try/except blocks to be as tight as possible so that wherever I happen to introduce an unexpected error I can track it down and not have it silently hidden

AC

  1. All try/except blocks should list after the except the specific exception(s) that can be handled cleanly.
  2. The contents of all try blocks should be reviewed to make sure they are as minimal as possible, i.e. they do not include code where we are not expecting the exception being caught.
  3. If a try/except block is being used to move past a condition that is undesirable/suspicious but not fatal, consider emitting a warning or printing some debug output so the user is aware of the condition.

Note

This ticket started out with a mandate to minimize the use of try and replace it with if/else logic where possible, but after some research I see that the use of try/except is idiomatic in python for reasons that make sense to me. However, even in python bare excepts and unnecessarily loose try content is considered harmful. This is proving to be a practical issue for me at the moment; I'm seeing an error in a database log but am having a hard time telling where the offending query is being generated because I'm not seeing a corresponding exception in python -- presumably because it's being caught somewhere!

mactyr commented 8 years ago

@sborgeson will review, with support from @mactyr as needed.

mactyr commented 8 years ago

Don't bother fixing util.currency_convert() on master because I've already fixed it on the data_access branch.