bug 1146035 - don't die when writing utf8 to file. r=jlund
authorAki Sasaki <aki@escapewindow.com>
Mon, 23 Mar 2015 23:32:51 -0700 (2015-03-24)
changeset 3810 99f52c1c19c8451ba81494b79f0814d49858117b
parent 3809 e18f4351eb5980465e064c54800a892ef8c72ed4
child 3811 2ca53a19719bbc633caa73eb7d7ccf586dd0bc42
push id3006
push useraki@escapewindow.com
push dateTue, 24 Mar 2015 06:33:22 +0000 (2015-03-24)
reviewersjlund
bugs1146035
bug 1146035 - don't die when writing utf8 to file. r=jlund
mozharness/base/script.py
--- 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',