Skip to content

Commit

Permalink
Fix a missed exception handling for bad plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Sep 13, 2020
1 parent c907b2e commit 987ceb9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion coverage/ctracer/tracer.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,8 @@ CTracer_handle_line(CTracer *self, PyFrameObject *frame)
STATS( self->stats.pycalls++; )
from_to = PyObject_CallMethodObjArgs(self->pcur_entry->file_tracer, str_line_number_range, frame, NULL);
if (from_to == NULL) {
goto error;
CTracer_disable_plugin(self, self->pcur_entry->disposition);
goto ok;
}
ret2 = CTracer_unpack_pair(self, from_to, &lineno_from, &lineno_to);
Py_DECREF(from_to);
Expand Down
22 changes: 22 additions & 0 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,28 @@ def coverage_init(reg, options):
""")
self.run_bad_plugin("bad_plugin", "Plugin")

def test_line_number_range_raises_error(self):
self.make_file("bad_plugin.py", """\
import coverage.plugin
class Plugin(coverage.plugin.CoveragePlugin):
def file_tracer(self, filename):
if filename.endswith("other.py"):
return BadFileTracer()
class BadFileTracer(coverage.plugin.FileTracer):
def source_filename(self):
return "something.foo"
def line_number_range(self, frame):
raise Exception("borked!")
def coverage_init(reg, options):
reg.add_file_tracer(Plugin())
""")
self.run_bad_plugin(
"bad_plugin", "Plugin", our_error=False, excmsg="borked!",
)

def test_line_number_range_returns_non_tuple(self):
self.make_file("bad_plugin.py", """\
import coverage.plugin
Expand Down

0 comments on commit 987ceb9

Please sign in to comment.