bug 1146035 - don't die when writing utf8 to file. r=jlund
--- a/mozharness/base/script.py
+++ b/mozharness/base/script.py
@@ -429,17 +429,20 @@ class ScriptMixin(object):
self.info("Contents:")
for line in contents.splitlines():
self.info(" %s" % line)
if create_parent_dir:
parent_dir = os.path.dirname(file_path)
self.mkdir_p(parent_dir, error_level=error_level)
try:
fh = open(file_path, open_mode)
- fh.write(contents)
+ try:
+ fh.write(contents)
+ except UnicodeEncodeError:
+ fh.write(contents.encode('utf-8', 'replace'))
fh.close()
return file_path
except IOError:
self.log("%s can't be opened for writing!" % file_path,
level=error_level)
@contextmanager
def opened(self, file_path, verbose=True, open_mode='r',