diff --git a/vigil b/vigil index ad966ee..d35a3c5 100755 --- a/vigil +++ b/vigil @@ -14,14 +14,14 @@ def punish(line, offense): if line == offend_line: return # Walk back to find the beginning of the function containing this line. - start = line + start = line-1 while start >= 0: if re.match('def ', source_lines[start]): break start -= 1 # Walk forward to find the end of the function. - end = line + end = line-1 while end < len(source_lines): if re.match('^\s*$', source_lines[end]): break @@ -32,7 +32,7 @@ def punish(line, offense): # Clear the lines, but don't delete them. That way later failures will # have the right line number. - for i in xrange(start, end + 1): + for i in xrange(start, end): source_lines[i] = '' def vigil_implore(ok, expr): @@ -72,7 +72,6 @@ def vigil_done(): def vigil_uncaught(): raise_line = traceback.extract_tb(sys.exc_info()[2])[-1][1] - print "uncaught error from line ", raise_line punish(raise_line, "Raised '%s' which was not caught." % sys.exc_info()[1]) with open(source_path) as f: @@ -87,8 +86,10 @@ with open(source_path) as f: try: main() except Exception as ex: - vigil_uncaught() + # Be forgiving of our own sins, for there must be someone left to carry out the deed + if ex.__class__.__name__ != "NameError" or ex.message.split("'")[1] != "main": + vigil_uncaught() vigil_done() """ - exec(source) + exec(source) \ No newline at end of file