Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions vigil
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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)