From 596062b0f974a57f65b3b99881bd5059e5c6b008 Mon Sep 17 00:00:00 2001
From: Ian Wienand <iwienand@redhat.com>
Date: Fri, 25 May 2018 11:05:02 +1000
Subject: [PATCH] Use surrogateescape with outfilter.py

When switching to using log-file capture, we're getting

 [gentoo/build-succeeds] outfile.write(ts_line.encode('utf-8'))
 [gentoo/build-succeeds] UnicodeEncodeError: 'utf-8' codec can't
   encode character 'udcc5' in position 59: surrogates not allowed

Use surrogateescape [1] on the output to avoid this

[1] https://www.python.org/dev/peps/pep-0383/

Change-Id: I2c2c537296edfa5a8fe661a41bd5bfb3bfcf57e3
---
 diskimage_builder/lib/outfilter.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/diskimage_builder/lib/outfilter.py b/diskimage_builder/lib/outfilter.py
index 728bcf402..71c196d57 100644
--- a/diskimage_builder/lib/outfilter.py
+++ b/diskimage_builder/lib/outfilter.py
@@ -78,7 +78,8 @@ def main():
             if sys.version_info < (3,):
                 outfile.write(ts_line)
             else:
-                outfile.write(ts_line.encode('utf-8'))
+                outfile.write(
+                    ts_line.encode('utf-8', errors='surrogateescape'))
             outfile.flush()