summaryrefslogtreecommitdiff
path: root/coverage/sqldata.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/sqldata.py')
-rw-r--r--coverage/sqldata.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/coverage/sqldata.py b/coverage/sqldata.py
index 01f5ce01..613a280c 100644
--- a/coverage/sqldata.py
+++ b/coverage/sqldata.py
@@ -1031,7 +1031,20 @@ class SqliteDb(SimpleReprMixin):
try:
return self.con.execute(sql, parameters)
except sqlite3.Error as exc:
- raise CoverageException("Couldn't use data file {!r}: {}".format(self.filename, exc))
+ msg = str(exc)
+ try:
+ # `execute` is the first thing we do with the database, so try
+ # hard to provide useful hints if something goes wrong now.
+ with open(self.filename, "rb") as bad_file:
+ cov4_sig = b"!coverage.py: This is a private format"
+ if bad_file.read(len(cov4_sig)) == cov4_sig:
+ msg = (
+ "Looks like a coverage 4.x data file. "
+ "Are you mixing versions of coverage?"
+ )
+ except Exception:
+ pass
+ raise CoverageException("Couldn't use data file {!r}: {}".format(self.filename, msg))
def executemany(self, sql, data):
"""Same as :meth:`python:sqlite3.Connection.executemany`."""