diff --git a/coverage/python.py b/coverage/python.py index 969bfa89c..e8974bb0b 100644 --- a/coverage/python.py +++ b/coverage/python.py @@ -63,7 +63,10 @@ def get_python_source(filename): # Replace \f because of http://bugs.python.org/issue19035 source = source.replace(b'\f', b' ') - source = source.decode(source_encoding(source), "replace") + try: + source = source.decode(source_encoding(source), "replace") + except Exception as e: + raise NoSource("Cannot decode source '%s: %s" % (filename, e)) # Python code should always end with a line with a newline. if source and source[-1] != '\n':