Bug 1299618 - [mozlint] Encode results to utf-8 before printing to stdout, r=smacleod
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Wed, 31 Aug 2016 17:18:52 -0400
changeset 312326 eeba75f09439f139fd21d7f62d47b60884b7a179
parent 312325 4686f24bce9724843410be75b309896d50ff33ea
child 312327 9f6df7f965bfb244e4245e184d4117f80d82d4eb
push id30642
push userkwierso@gmail.com
push dateFri, 02 Sep 2016 19:52:35 +0000
treeherdermozilla-central@38d0defa2db7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmacleod
bugs1299618
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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))