Open adirizka7 opened 4 years ago
Can you upload the .coverage file or provide details about where it came from? The error suggests the file is not a valid python coverage file.
Sure, here is the file https://drive.google.com/file/d/1SpHT06QoMvtz13NyQkM6UeOGoDSuI25W/view?usp=sharing .
It works fine when I run coverage html
tho.
Looks like i figured it out, previous .coverage file was produced by using --cov-report term
. I updated the args to --cov-report html
and the cov.load() works fine. Thanks!
oh no, it only works in separate python file
(venv) ➜ tinydb git:(master) ✗ python3
Python 3.6.11 (heads/master-dirty:86df475, Jul 31 2020, 00:00:00)
[GCC 9.3.1 20200408 (Red Hat 9.3.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from coverage import Coverage
>>> cov = Coverage()
>>> cov.load()
>>>
but error still occurs when running ':CoverageShow'
And the same error from :CoverageShow
, or slightly different?
Might also be room to improve that error if we can narrow down a clear failure scenario and how to detect it in our code.
It was the same error. Turns out the error occurs because I forgot to activate virtualenv and I was using the older version of coverage in my os.
$ pip freeze | grep coverage
coverage==4.5.4
It's working fine when I use the newer 5.2.1
version.
can we catch this kind of error and rewrite it to a more informative error ?
Oof, yeah, I'd hope we could detect those kinds of trivial format compatibility issues, but that error from coverage is pretty nonspecific. Do you know if there's any helper to inspect the old format or good heuristic to check for files in the old format?
I've searched for the correct pytest version that produced the older format, but sadly, I couldn't find any. Best I can think of right now is to catch this error UnicodeDecodeError
and rewrite it to something like coverage data is not valid, check your coverage version ....
:+1: I imagine providing a little context and trimming out some of the noise from that error would be a major improvement. In this case the one CoverageException line contains the essential info. Ideally the error would look something like
ERROR: ShowCoverage failed to read coverage file: coverage.misc.CoverageException: Couldn't read data from '/home/fedora/Desktop/GIT/tinydb/.coverage': UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf0 in position 99: invalid continuation byte
.
That said, could take me quite some time to get around to submitting a fix. Contributions would be very welcome!
Nice, I'll find some time to work on this one if that's ok
Yes, that would be great!
You can include the coverage version from coverage.__version__
in the error message and just say it expected a coverage file compatible with that, check for mixed installations, and regenerate .coverage if needed. And then try to keep the original error message included in some form in case there's another cause for errors like a bug in the coverage library that the user would need to troubleshoot.
Having the same issue. The traceback tells that plugin tries to read file .coverage
as UTF-8 text, whereas it is actually an SQLite database:
$ file .coverage
.coverage: SQLite 3.x database, last written using SQLite version 3022000
That is the case since coveragepy==5.0a2. The code supporting JSON format has then been removed in coveragepy==5.0a6.
Just tested that reverting to coveragepy==4.5.4
fixes the issue.
Oh, so probably it was the same unsupported SQLite issue all along! That sounds like we could catch and give a much more user-friendly message for this case, when it hits a UnicodeDecodeError
trying to decode a file that's actually SQLite.
lib version