"git review --setup" failed in Chinese locale
If a subcommand's output includes a non-ASCII character, the following occurs: [nova]$ LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 git review --setup Traceback (most recent call last): File "/usr/bin/git-review", line 1187, in <module> print(e) UnicodeEncodeError: 'ascii' codec can't encode characters in position 180-183: ordinal not in range(128) Python3 works, because we force-encode everyting in run_command_status. Change-Id: Ic4f4b0df57068c356a670901e02bf00c33985e2c
This commit is contained in:
@@ -1155,5 +1155,14 @@ if __name__ == "__main__":
|
|||||||
try:
|
try:
|
||||||
main()
|
main()
|
||||||
except GitReviewException as e:
|
except GitReviewException as e:
|
||||||
print(e)
|
# If one does unguarded print(e) here, in certain locales the implicit
|
||||||
|
# str(e) blows up with familiar "UnicodeEncodeError ... ordinal not in
|
||||||
|
# range(128)". See rhbz#1058167.
|
||||||
|
try:
|
||||||
|
u = unicode(e)
|
||||||
|
except NameError:
|
||||||
|
# Python 3, we're home free.
|
||||||
|
print(e)
|
||||||
|
else:
|
||||||
|
print(u.encode('utf-8'))
|
||||||
sys.exit(e.EXIT_CODE)
|
sys.exit(e.EXIT_CODE)
|
||||||
|
Reference in New Issue
Block a user