From 9837f70516984d51a6011cccfa2819b85ba9da64 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Thu, 12 Jan 2023 08:51:52 +0800 Subject: [PATCH 1/2] Add safety for empty stack on shutdown. --- coverage/pytracer.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/coverage/pytracer.py b/coverage/pytracer.py index 326c50ba8..94427d691 100644 --- a/coverage/pytracer.py +++ b/coverage/pytracer.py @@ -137,9 +137,12 @@ 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: From 607370d12eef00e183d1dd2cdff4d78d0d34b822 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Tue, 24 Jan 2023 12:05:26 +0800 Subject: [PATCH 2/2] Correct line length linting issue. --- coverage/pytracer.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/coverage/pytracer.py b/coverage/pytracer.py index 94427d691..6723c2a1b 100644 --- a/coverage/pytracer.py +++ b/coverage/pytracer.py @@ -142,7 +142,12 @@ def _trace( self.data_stack.pop() ) except IndexError: - self.log("Empty stack!", frame.f_code.co_filename, frame.f_lineno, frame.f_code.co_name) + 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: