-
Notifications
You must be signed in to change notification settings - Fork 283
gcovr crashes with files which are not utf-8 encoded #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We have exactly the same issue since we updated gcvor from 3.2 to 3.3 |
It's kind of random, it doesn't always fail on the same file, mostly on our files though. |
Its seems that I'm facing the issue with v3.2 when I install from source code. |
Source files may not be properly encoded. Make the handling of such files more tolerant. Fixes gcovr#148.
Source files may not be properly encoded. While the compiler and gcov do not care it will blow up Python 3 that expects proper encoding. Make the handling of such files more tolerant by using the 'surrogateescape' error policy. On the other hand Python 2 does not care about the encoding. Wrap the open() function there to add the missing 'errors' parameter. Fixes gcovr#148.
Facing the same issue. Not getting any clue on what is causing this issue. Traceback (most recent call last): |
As a workaround, using gcovr under Python 2.7 might sidestep these issues when using a single-byte encoding. The gcovr source currently ignores file encoding. The PR #157 suggests a way to address these issues (inserting replacement characters when the input doesn't decode via UTF-8), but I think that solution is mostly wrong because it doesn't actually support non-UTF-8 encodings – it just paints over any errors. The I think the correct solution is to adapt #157 and introduce a I'm deferring this issue because other tasks have to be done first, but I understand that gcovr is broken regarding encodings and needs to be fixed. |
It's a good idea to introduce something like It's amazing, but I've got some problems even with utf-8 encoded sources on Windows (python 3.6)! It seems like there is more than one default encoding:
They can differ. It seems that default encoding for So, if source code is in that encoding (no matter utf-8 or not) - you are lucky and it's just enough to adjust html reports encoding produced by If your source code is not in that encoding
The only simple way to get it work is to implicitly set As far as I know, Python 2.7 reads files "as is", |
I've got some sources in utf-8 encoding. diff --git a/scripts/gcovr b/scripts/gcovr
index abc8108..3ecc8a1 10
8000
0755
--- a/scripts/gcovr
+++ b/scripts/gcovr
@@ -456,7 +456,7 @@ def is_non_code(code):
# Process a single gcov datafile
#
def process_gcov_data(data_fname, covdata, source_fname, options):
- INPUT = open(data_fname, "r")
+ INPUT = open(data_fname, "r", encoding='utf-8')
#
# Get the filename
#
@@ -1716,7 +1716,7 @@ def print_html_report(covdata, details):
data['ROWS'] = []
currdir = os.getcwd()
os.chdir(root_dir)
- INPUT = open(data['FILENAME'], 'r')
+ INPUT = open(data['FILENAME'], 'r', encoding='utf-8')
ctr = 1
for line in INPUT:
data['ROWS'].append(
@@ -1728,7 +1728,7 @@ def print_html_report(covdata, details):
data['ROWS'] = '\n'.join(data['ROWS'])
htmlString = source_page.substitute(**data)
- OUTPUT = open(cdata._sourcefile, 'w')
+ OUTPUT = open(cdata._sourcefile, 'w', encoding='utf-8')
OUTPUT.write(htmlString + '\n')
OUTPUT.close() In this case |
Source file encoding support has been implemented in #256. If it doesn't address your use case, please add a comment with more information. |
Sorry for late answer. OS: Windows, Python version: 3.6, encodings:
P. S. Special thanks to @lisongmin! |
Uh oh!
There was an error while loading. Please reload this page.
Unfortunately we have some submodules which are not utf-8 encoded.
If we run gcovr on our project, we got a backtrace:
In projects where all files are utf-8 encoded everything works fine.
We are using gcovr-3.3.
The text was updated successfully, but these errors were encountered: