From c8bb1bddeff46a5f3b553c3051118b5757f2f35c Mon Sep 17 00:00:00 2001 From: Ahir Reddy Date: Wed, 10 Feb 2021 13:35:09 -0800 Subject: [PATCH] Handle UTF-8 output in all environments Python auto-detects the default string encoding based on several environment variables: ``` LANG=C.UTF-8 LC_CTYPE=en_US.UTF-8 ``` These are set by default in shells Devbox, and thus the encoding used by default is UTF-8. However, when invoking the git-shim from a shell where these variables are not set or as a subprocess (like from the test-shard CLI) - the default encoding is ASCII. This results in the following error whenever UTF-8 is present in the output of any command (usually a diff) ``` UnicodeEncodeError: 'ascii' codec can't encode characters in position -: ordinal not in range(128) ``` This PR fixes the issue by explicitly setting the encoding of the printed output to UTF-8 - so we don't need to rely on it being properly set in the environment or by callers. --- launcher/resources/git-shim.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/resources/git-shim.py b/launcher/resources/git-shim.py index 16e9eb3..50088a3 100755 --- a/launcher/resources/git-shim.py +++ b/launcher/resources/git-shim.py @@ -60,7 +60,7 @@ def handle_intrinsic(root): # is the exit code of the completed command if len(response) == 2: if response[0] == 0: - print(response[1]) + print(response[1].encode('utf-8')) elif response[0] == 1: sys.exit(response[1]) else: