Skip to content

Commit ae9bdf5

Browse files
committed
xcresult_logs.py: change the UnicodeEncodeError avoidance strategy to instead just encode to UTF-8 in a relaxed manner and write the resulting bytes directly to stdout
1 parent 2ecfbd6 commit ae9bdf5

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

scripts/xcresult_logs.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,11 @@ def main():
6565
log_id = find_log_id(xcresult_path)
6666
log = export_log(xcresult_path, log_id)
6767

68-
# Avoid UnicodeEncodeError by adapting the code example from
69-
# https://docs.python.org/3/library/sys.html#sys.displayhook
70-
try:
71-
sys.stdout.write(log)
72-
except UnicodeEncodeError:
73-
log_encoded = log.encode(sys.stdout.encoding, errors='backslashreplace')
74-
if hasattr(sys.stdout, 'buffer'):
75-
sys.stdout.flush()
76-
sys.stdout.buffer.write(log_encoded)
77-
else:
78-
log_decoded = log_encoded.decode(sys.stdout.encoding, errors='strict')
79-
sys.stdout.write(log_decoded)
68+
# Avoid a potential UnicodeEncodeError raised by sys.stdout.write() by
69+
# doing a relaxed encoding ourselves and writing the resulting bytes.
70+
log_encoded = log.encode('utf8', errors='backslashreplace')
71+
sys.stdout.flush()
72+
sys.stdout.buffer.write(log_encoded)
8073

8174

8275
# Most flags on the xcodebuild command-line are uninteresting, so only pull

0 commit comments

Comments
 (0)