From 982eca893a895db262ae56650bd05d9f7ab6a076 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 10 Oct 2021 12:52:10 -0400 Subject: fix: raise CoverageException for SQLite connection errors --- coverage/sqldata.py | 6 +++++- tests/test_data.py | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/coverage/sqldata.py b/coverage/sqldata.py index c4e950d3..2411fbca 100644 --- a/coverage/sqldata.py +++ b/coverage/sqldata.py @@ -1032,7 +1032,11 @@ class SqliteDb(SimpleReprMixin): # is not a problem. if self.debug: self.debug.write(f"Connecting to {self.filename!r}") - self.con = sqlite3.connect(self.filename, check_same_thread=False) + try: + self.con = sqlite3.connect(self.filename, check_same_thread=False) + except sqlite3.Error as exc: + raise CoverageException(f"Couldn't use data file {self.filename!r}: {exc}") from exc + self.con.create_function("REGEXP", 2, _regexp) # This pragma makes writing faster. It disables rollbacks, but we never need them. diff --git a/tests/test_data.py b/tests/test_data.py index 0660591f..735a12b3 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -598,6 +598,14 @@ class CoverageDataInTempDirTest(CoverageTest): covdata.read() assert not covdata + def test_hard_read_error(self): + self.make_file("noperms.dat", "go away") + os.chmod("noperms.dat", 0) + msg = r"Couldn't .* '.*[/\\]{}': \S+" + with pytest.raises(CoverageException, match=msg.format("noperms.dat")): + covdata = DebugCoverageData("noperms.dat") + covdata.read() + def test_read_sql_errors(self): with sqlite3.connect("wrong_schema.db") as con: con.execute("create table coverage_schema (version integer)") -- cgit v1.2.1