You will like the final version of the traperr ERR function. It looks to create a "stack trace" type dump of where you are in the script when it fails.
See it here: https://github.com/pottmi/stringent.sh