blue-marble / gridpath

A versatile simulation and optimization platform for power-system planning and operations.
https://www.gridpath.io
Apache License 2.0
94 stars 36 forks source link

Fix misleading error messages on module import #298

Open gerritdm opened 4 years ago

gerritdm commented 4 years ago

Right now, the load_subtype_modules() function in auxiliary.py will print the following message when the import fails, regardless of the cause: "ERROR! Subtype module gen_commit_bin not found.”

This can be misleading when the cause is actually a syntax error or something else within the module being imported, rather than an issue with finding the module.

anamileva commented 4 years ago

Any suggestions for how to fix this?

gerritdm commented 4 years ago

I think the easiest solution would be to simply clarify the error message and say something like: "ERROR! Subtype module " + m + " could not be imported. Possible causes: module does not exist, module has syntax errors, ..." (I'm sure there are more possible causes)

I'm not sure if it's possible but a more advanced solution could be to try and catch the errors separately so you would differentiate between an error arising from trying to import a non-existing module vs. a syntax error within the module you're trying to import

anamileva commented 4 years ago

Just a note that we catch the ImportError a number of places in the code (it's all over the place in the testing suite), so it probably makes sense to think about a more general refactor.

734 does add traceback when the error is caught in load_subtype_modules in gridpath.auxiliary.auxiliary