EnergyPATHWAYS model is a professional, open-source energy and carbon planning tool for use in evaluating long-term, economy-wide greenhouse gas mitigation scenarios.
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
All try/except blocks should list after the except the specific exception(s) that can be handled cleanly.
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.
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!
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 hiddenAC
try/except
blocks should list after theexcept
the specific exception(s) that can be handled cleanly.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.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 loosetry
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!