Bug 1299618 - [mozlint] Encode results to utf-8 before printing to stdout, r?smacleod draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Wed, 31 Aug 2016 17:18:52 -0400
changeset 408846 356d7576ef8e035402491d8f72f0502f8ecaf8b8
parent 408345 9e00b305da24074ae5aba1227beb5e096b026100
child 530181 c4edd325d6ba8f9d456799ce232558bc97792877
push id28289
push userahalberstadt@mozilla.com
push dateThu, 01 Sep 2016 17:48:40 +0000
reviewerssmacleod
bugs1299618
milestone51.0a1
Bug 1299618 - [mozlint] Encode results to utf-8 before printing to stdout, r?smacleod MozReview-Commit-ID: 93RAqIRKAHc
python/mozlint/mozlint/cli.py
--- a/python/mozlint/mozlint/cli.py
+++ b/python/mozlint/mozlint/cli.py
@@ -96,16 +96,20 @@ def run(paths, linters, fmt, rev, workdi
 
     lint = LintRoller(**lintargs)
     lint.read(find_linters(linters))
 
     # run all linters
     results = lint.roll(paths, rev=rev, workdir=workdir)
 
     formatter = formatters.get(fmt)
-    print(formatter(results))
+
+    # Explicitly utf-8 encode the output as some of the formatters make
+    # use of unicode characters. This will prevent a UnicodeEncodeError
+    # on environments where utf-8 isn't the default
+    print(formatter(results).encode('utf-8', 'replace'))
     return 1 if results else 0
 
 
 if __name__ == '__main__':
     parser = MozlintParser()
     args = vars(parser.parse_args())
     sys.exit(run(**args))