Skip to content

Commit 982eca8

Browse files
committed
fix: raise CoverageException for SQLite connection errors
1 parent 4144f95 commit 982eca8

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

coverage/sqldata.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,11 @@ def _connect(self):
10321032
# is not a problem.
10331033
if self.debug:
10341034
self.debug.write(f"Connecting to {self.filename!r}")
1035-
self.con = sqlite3.connect(self.filename, check_same_thread=False)
1035+
try:
1036+
self.con = sqlite3.connect(self.filename, check_same_thread=False)
1037+
except sqlite3.Error as exc:
1038+
raise CoverageException(f"Couldn't use data file {self.filename!r}: {exc}") from exc
1039+
10361040
self.con.create_function("REGEXP", 2, _regexp)
10371041

10381042
# This pragma makes writing faster. It disables rollbacks, but we never need them.

tests/test_data.py

+8
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,14 @@ def test_read_errors(self):
598598
covdata.read()
599599
assert not covdata
600600

601+
def test_hard_read_error(self):
602+
self.make_file("noperms.dat", "go away")
603+
os.chmod("noperms.dat", 0)
604+
msg = r"Couldn't .* '.*[/\\]{}': \S+"
605+
with pytest.raises(CoverageException, match=msg.format("noperms.dat")):
606+
covdata = DebugCoverageData("noperms.dat")
607+
covdata.read()
608+
601609
def test_read_sql_errors(self):
602610
with sqlite3.connect("wrong_schema.db") as con:
603611
con.execute("create table coverage_schema (version integer)")

0 commit comments

Comments
 (0)