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 312336 eeba75f09439f139fd21d7f62d47b60884b7a179
parent 312335 4686f24bce9724843410be75b309896d50ff33ea
child 312337 9f6df7f965bfb244e4245e184d4117f80d82d4eb
push id20447
push userkwierso@gmail.com
push dateFri, 02 Sep 2016 20:36:44 +0000
treeherderfx-team@969397f22187 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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))