Skip to content

{Core} Always use UTF-8 for command metadata log file encoding - #17996

Merged
Jiashuo Li (jiasli) merged 2 commits into
Azure:devfrom
jiasli:encoding
May 8, 2021
Merged

Jiashuo Li (jiasli) merged 2 commits into
Azure:devfrom
jiasli:encoding

Conversation

@jiasli

Copy link
Copy Markdown
Contributor

Fix #17994
Adopt microsoft/knack#247

Context

On Windows with English as the system language (without UTC-8 enabled), the system encoding by default is cp1252 (Western Europe), and Python will use cp1252 as the file encoding by default.

Writing Unicode characters like 汉字 to log file results in error:

Traceback (most recent call last):
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\logging\__init__.py", line 1084, in emit
    stream.write(msg + self.terminator)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 87-88: character maps to <undefined>

Change

This PR forces command metadata log files to use UTF-8 so that az feedback works on non-UTF-8 systems as well.

@yonzhan

Copy link
Copy Markdown
Collaborator

Core

@yonzhan Yong Zhang (yonzhan) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jiasli

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@jiasli
Jiashuo Li (jiasli) merged commit 0914bac into Azure:dev May 8, 2021
@jiasli
Jiashuo Li (jiasli) deleted the encoding branch May 8, 2021 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to print special characters to console output

3 participants