refactored error handling, less error prone

relates to the bug fixed here: http://article.gmane.org/gmane.comp.lang.lua.luarocks/3972 


NOTE: not related to the RC, just a general refactor