To identify run-time errors :
you can place various print "message #i" statements within the script and run the whole script.
Thus, you can identify the code portion generating the error as the set of code lines between the last printed message and first not printed message. Through several iterations, you can identify exactly the line causing the error.