Bug 1299618 - [mozlint] Encode results to utf-8 before printing to stdout, r?smacleod
MozReview-Commit-ID: 93RAqIRKAHc
--- 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))