Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix parsing error #20

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
25 changes: 17 additions & 8 deletions backtrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,35 +218,40 @@ def _extract_traceback(text):
if text.count(TRACEBACK_IDENTIFIER) == 2:
ignore_trace = True

for index, line in enumerate(text):
for line in text:
if TRACEBACK_IDENTIFIER in line:
if ignore_trace:
ignore_trace = False
continue
capture = True
location_info = True
# We're not capturing and making sure we only read lines
# with spaces since, after the initial identifier, all traceback lines
# contain a prefix spacing.
elif capture and line.startswith(' '):
if index % 2 == 0:
if location_info:
# Line containing a file, line and module.
line = line.strip().strip('\n')
next_line = text[index + 1].strip('\n')
entries.append(line + ', ' + next_line)
line = line.strip()
entries.append(line)
else:
# The corresponding line of source code.
line = line.rstrip("\n")
entries[-1] += ', ' + line
location_info = not location_info
elif capture:
# Line containing the module call.
entries.append(line)
break
else:
# Add everything else after the traceback.
# Add everything else before the traceback.
all_else.append(line)

traceback_entries = []

# Build the traceback structure later passed for formatting.
for index, line in enumerate(entries[:-2]):
# TODO: This should be done in a _parse_entry function
element = line.split(',')
element = line.split(',', 3)
element[0] = element[0].strip().lstrip('File').strip(' "')
element[1] = element[1].strip().lstrip('line').strip()
element[2] = element[2].strip().lstrip('in').strip()
Expand All @@ -264,7 +269,11 @@ def _stdin_hook(args):

tb, all_else = _extract_traceback(output)
sys.stdout.write(''.join(all_else))
tpe, value = output[-1].strip('\n').split(': ', 1)
try:
tpe, value = output[-1].strip('\n').split(': ', 1)
except ValueError:
tpe = output[-1].strip('\n')
value = ""
hook(
reverse=args.reverse,
align=args.align,
Expand Down