Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azure-cli crash when redirecting output #13413

Closed
johanburati opened this issue May 9, 2020 · 8 comments
Closed

azure-cli crash when redirecting output #13413

johanburati opened this issue May 9, 2020 · 8 comments
Assignees

Comments

@johanburati
Copy link
Contributor

azure-cli crash when redirecting output to some commands:

$ az --version | head -1
azure-cli                          2.5.1
The command failed with an unexpected error. Here is the traceback:

[Errno 32] Broken pipe
Traceback (most recent call last):
  File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 207, in invoke
    self.show_version()
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 108, in show_version
    print(ver_string)
  File "/opt/az/lib/python3.6/site-packages/colorama/ansitowin32.py", line 41, in write
    self.__convertor.write(text)
  File "/opt/az/lib/python3.6/site-packages/colorama/ansitowin32.py", line 162, in write
    self.write_and_convert(text)
  File "/opt/az/lib/python3.6/site-packages/colorama/ansitowin32.py", line 190, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "/opt/az/lib/python3.6/site-packages/colorama/ansitowin32.py", line 196, in write_plain_text
    self.wrapped.flush()
BrokenPipeError: [Errno 32] Broken pipe

To open an issue, please run: 'az feedback'
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
BrokenPipeError: [Errno 32] Broken pipe

$ cat /etc/os-release | head  -1
NAME="Ubuntu"

$ az --version | tail -1
and let us know if you're interested in trying out our newest features: https://aka.ms/CLIUXstudy

Same issue has already been reported previously in #58 and #770, those are now closed but still seeing the issue.

Environment

Linux-4.15.0-1082-azure-x86_64-with-debian-stretch-sid
Python 3.6.5
Installer: DEB

azure-cli 2.5.1
@ghost ghost added the needs-triage This is a new issue that needs to be triaged to the appropriate team. label May 9, 2020
@ghost ghost removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label May 9, 2020
@yonzhan yonzhan added this to the S169 - For Build milestone May 9, 2020
@yonzhan
Copy link
Collaborator

yonzhan commented May 9, 2020

@fengzhou-msft please take a look

@fengzhou-msft
Copy link
Member

fengzhou-msft commented May 9, 2020

The issue is caused by the colorama code for survey link.
You can turn off the link with export AZURE_OUTPUT_SHOW_SURVEY_LINK=False or disable the color for all command output with export AZURE_CORE_NO_COLOR=True.

For the purpose of parsing Azure CLI version, we recommend az version, the output is a simple json. az version --query '"azure-cli"' gives you the version "2.5.1" on Linux.

@fengzhou-msft
Copy link
Member

@jiasli anything we can do in kanck or core to catch the BrokenPipeError?

@jiasli
Copy link
Member

jiasli commented May 13, 2020

We shouldn't enable color if stdout is not a TTY. Fixed it in Knack.

@fengzhou-msft fengzhou-msft removed this from the S169 - For Build milestone Jun 9, 2020
@yungezz yungezz added the OKR3.4 Candidate For OKR3.4 label Dec 7, 2020
@johanburati
Copy link
Contributor Author

Still crashing to this day, any plan to fix this ?

johan@Azure:~$ az --version | head
azure-cli                         2.16.0 *

You have 2 updates available. They will be updated with the next build of Cloud Shell.
core                              2.16.0 *
telemetry                          1.0.6

Extensions:
webapp                            0.2.20
vm-repair                          0.1.2
azure-devops                      0.18.0
kusto                              0.2.0
CLIInternalError: The command failed with an unexpected error. Here is the traceback:
[Errno 32] Broken pipe
Traceback (most recent call last):
  File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 207, in invoke
    self.show_version()
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 115, in show_version
    print(UX_SURVEY_PROMPT_COLOR if self.enable_color else UX_SURVEY_PROMPT)
  File "/opt/az/lib/python3.6/site-packages/colorama/ansitowin32.py", line 41, in write
    self.__convertor.write(text)
  File "/opt/az/lib/python3.6/site-packages/colorama/ansitowin32.py", line 162, in write
    self.write_and_convert(text)
  File "/opt/az/lib/python3.6/site-packages/colorama/ansitowin32.py", line 187, in write_and_convert
    self.write_plain_text(text, cursor, start)
  File "/opt/az/lib/python3.6/site-packages/colorama/ansitowin32.py", line 196, in write_plain_text
    self.wrapped.flush()
BrokenPipeError: [Errno 32] Broken pipe
To open an issue, please run: 'az feedback'
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
BrokenPipeError: [Errno 32] Broken pipe

@jiasli
Copy link
Member

jiasli commented Jan 8, 2021

This issue will be fixed in the next release. Please see my comment at #13979 (comment).

@jiasli jiasli closed this as completed Jan 20, 2021
@johanburati
Copy link
Contributor Author

Thanks !

$ az --version | head -1
azure-cli                         2.18.0
$

@jiasli
Copy link
Member

jiasli commented Mar 11, 2021

I re-thought about this issue today and it is actually a colorama bug with head command (linked above 👆).

Anyway, we no longer init colorama if stdout is not a TTY, so we are good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants