Skip to content

Commit

Permalink
fix: add safety for empty stack on shutdown. (#1543)
Browse files Browse the repository at this point in the history
* Add safety for empty stack on shutdown.

* Correct line length linting issue.

---------

Co-authored-by: Ned Batchelder <ned@nedbatchelder.com>
  • Loading branch information
freakboy3742 and nedbat authored Feb 3, 2023
1 parent b0566a7 commit 96af3ea
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions coverage/pytracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,17 @@ def _trace(
self.log(">", f.f_code.co_filename, f.f_lineno, f.f_code.co_name, f.f_trace)
f = f.f_back
sys.settrace(None)
self.cur_file_data, self.cur_file_name, self.last_line, self.started_context = (
self.data_stack.pop()
)
try:
self.cur_file_data, self.cur_file_name, self.last_line, self.started_context = (
self.data_stack.pop()
)
except IndexError:
self.log(
"Empty stack!",
frame.f_code.co_filename,
frame.f_lineno,
frame.f_code.co_name
)
return None

# if event != 'call' and frame.f_code.co_filename != self.cur_file_name:
Expand Down

0 comments on commit 96af3ea

Please sign in to comment.