Skip to content

Commit

Permalink
Fix problem with lineno being none when generating traceback (#1750)
Browse files Browse the repository at this point in the history
* Fix problem with lineno being none when generating traceback

Fixes #1745

* Improve multiline statement handling in stack summary
  • Loading branch information
rchiodo authored Dec 2, 2024
1 parent f4ba976 commit 3823aba
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1523,12 +1523,22 @@ def build_exception_info_response(dbg, thread_id, thread, request_seq, set_addit
if IS_PY311_OR_GREATER:
stack_summary = traceback.StackSummary()
for filename_in_utf8, lineno, method_name, line_text, line_col_info in frames[-max_frames:]:
frame_summary = traceback.FrameSummary(filename_in_utf8, lineno, method_name, line=line_text)
if line_col_info is not None:
frame_summary.end_lineno = line_col_info.end_lineno
frame_summary.colno = line_col_info.colno
frame_summary.end_colno = line_col_info.end_colno
stack_summary.append(frame_summary)
# End line might mean that we have a multiline statement.
if line_col_info.end_lineno is not None and lineno < line_col_info.end_lineno:
line_text = "\n".join(linecache.getlines(filename_in_utf8)[lineno : line_col_info.end_lineno + 1])
frame_summary = traceback.FrameSummary(
filename_in_utf8,
lineno,
method_name,
line=line_text,
end_lineno=line_col_info.end_lineno,
colno=line_col_info.colno,
end_colno=line_col_info.end_colno)
stack_summary.append(frame_summary)
else:
frame_summary = traceback.FrameSummary(filename_in_utf8, lineno, method_name, line=line_text)
stack_summary.append(frame_summary)

stack_str = "".join(stack_summary.format())

Expand Down

0 comments on commit 3823aba

Please sign in to comment.