Skip to content

Show warning when UnicodeEncodeError is raised - #178

Merged
Jiashuo Li (jiasli) merged 1 commit into
microsoft:masterfrom
jiasli:encoding-warning
Mar 10, 2020
Merged

Jiashuo Li (jiasli) merged 1 commit into
microsoft:masterfrom
jiasli:encoding-warning

Conversation

@jiasli

@jiasli Jiashuo Li (jiasli) commented Mar 3, 2020

Copy link
Copy Markdown
Contributor

Show warning when UnicodeEncodeError is raised.

To test, on Windows go to Control Panel > Region > Administrative > Change system local and use English. Do not check Beta: Use Unicode UTF-8 for worldwide language support.

Open PowerShell terminal and run

az group show -n testrg
{
  "id": "/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/resourceGroups/testrg",
  "location": "centralus",
  "managedBy": null,
  "name": "testrg",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": {
    "key0303": "测试€£¥テスト안녕𓀀𓀁𒀉𒅤"
  },
  "type": "Microsoft.Resources/resourceGroups"
}

The output is correct, but if the output is redirected, PowerShell uses the system encoding. Thus az will silently remove the value of key0303:

> $t = az group show -n testrg
> $t
{
  "id": "/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/resourceGroups/testrg",
  "location": "centralus",
  "managedBy": null,
  "name": "testrg",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": {
    "key0303": ""   // value is removed
  },
  "type": "Microsoft.Resources/resourceGroups"
}

The solution is any of

  1. Remove invalid characters under the current locale
  2. Use a locale that supports those special characters
  3. Check Beta: Use Unicode UTF-8 for worldwide language support

utf8

If none of the above solution is adopted, Knack will show a warning:

> $t = az group show -n testrg
Unable to encode the output with cp1252 encoding. Unsupported characters are discarded.**

@jiasli

Copy link
Copy Markdown
Contributor Author

Shuai Wang (@shenmuxiaosen), please let me know if this solves the issue.

@shenmuxiaosen

Copy link
Copy Markdown

Shuai Wang (@shenmuxiaosen), please let me know if this solves the issue.

Yes, the problem resolved after applying the solution 3.

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.

4 participants