From be5178fda38750c0aae78061bf1b1bf3397a467d Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Wed, 11 Jun 2014 22:02:32 -0400 Subject: Prevent UnicodeDecodeErrors in html report. #303 --- coverage/html.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'coverage/html.py') diff --git a/coverage/html.py b/coverage/html.py index 6c811107..85f47ab4 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -238,15 +238,9 @@ class HtmlReporter(Reporter): })) if sys.version_info < (3, 0): - try: - html = html.decode(encoding) - except UnicodeDecodeError as e: - sample = e.object[max([0, e.start-30]):e.start+30] - raise CoverageException( - "Couldn't decode %r as %s: %r" % ( - cu.filename, e.encoding, sample - ) - ) + # In theory, all the characters in the source can be decoded, but + # strange things happen, so use 'replace' to keep errors at bay. + html = html.decode(encoding, 'replace') html_filename = flat_rootname + ".html" html_path = os.path.join(self.directory, html_filename) -- cgit v1.2.1