Commit 19443ec0 authored by Zhengxu Chen's avatar Zhengxu Chen Committed by Facebook GitHub Bot

Specify error handler for text encoding in logging functions.

Summary: Currently output from build command is decoded with "surrogateescape" error handler, but when writing to log files/stdout we don't specify error handlers to be also "surrogateescape" according to https://docs.python.org/3/library/codecs.html#error-handlers, which could cause exception when there's surrogate characters logged in message.

Reviewed By: yfeldblum

Differential Revision: D21850411

fbshipit-source-id: 21c51d1ab2132171ae29f2d1fbe42655ebee94c5
parent 94ed107a
......@@ -47,19 +47,22 @@ def _print_env_diff(env):
def run_cmd(cmd, env=None, cwd=None, allow_fail=False, log_file=None):
def log_to_stdout(msg):
sys.stdout.buffer.write(msg.encode(errors="surrogateescape"))
if log_file is not None:
with open(log_file, "a") as log:
with open(log_file, "a", errors="surrogateescape") as log:
def log_function(msg):
log.write(msg)
sys.stdout.write(msg)
log_to_stdout(msg)
return _run_cmd(
cmd, env=env, cwd=cwd, allow_fail=allow_fail, log_fn=log_function
)
else:
return _run_cmd(
cmd, env=env, cwd=cwd, allow_fail=allow_fail, log_fn=sys.stdout.write
cmd, env=env, cwd=cwd, allow_fail=allow_fail, log_fn=log_to_stdout
)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment