[Container App] Fix az containerapp exec crash on non-ASCII (emoji) terminal output#33476
[Container App] Fix az containerapp exec crash on non-ASCII (emoji) terminal output#33476after2842 wants to merge 1 commit into
az containerapp exec crash on non-ASCII (emoji) terminal output#33476Conversation
|
Validation for Azure CLI Full Test Starting...
Thanks for your contribution! |
|
Validation for Breaking Change Starting...
Thanks for your contribution! |
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds resilient terminal output handling for the Container Apps SSH exec session so that characters not representable in the host console's encoding (e.g., emoji on a cp1252 Windows terminal) don't crash the session.
Changes:
- Introduced
_write_to_terminalhelper that prints normally when possible and falls back to encoding withbackslashreplaceviasys.stdout.bufferwhen the console codec cannot encode the text. - Refactored
_decode_and_output_to_terminalto decode first, then route output through the new helper; also fixed a misleading log message ("encode" -> "decode"). - Added unit tests covering the fast path, the unencodable-character fallback, and end-to-end decode+output behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/azure-cli/azure/cli/command_modules/containerapp/_ssh_utils.py | New _write_to_terminal fallback writer; _decode_and_output_to_terminal reworked to use it and corrected log wording. |
| src/azure-cli/azure/cli/command_modules/containerapp/tests/latest/test_ssh_utils.py | New tests verifying fast path, encoding fallback, and that emoji output does not disconnect. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| decoded = response[2:].decode(encoding) | ||
| break |
|
@microsoft-github-policy-service agree |
Related command
az containerapp execDescription
az containerapp execcrashes withUnicodeEncodeErrorwhenever a container'sstdout/stderr contains characters the local terminal's codec cannot encode
(emoji, non-Latin scripts). On a cp1252 Windows console, e.g. the lobster emoji
U+1F99E:UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f99e' ...
File "_ssh_utils.py", line 108, in _decode_and_output_to_terminal
Root cause: in
_decode_and_output_to_terminal, the container bytes decode to astrcorrectly (UTF-8), butprint()then re-encodes thatstrto theconsole's encoding (cp1252), which raises
UnicodeEncodeError. The surroundingtry/exceptonly caughtUnicodeDecodeError, so the encode-side failure wasuncaught and tore down the exec session.
Fix: route terminal output through a new
_write_to_terminal()helper thatprints natively on capable (UTF-8) terminals, and on
UnicodeEncodeErrorfallsback to encoding with
errors="backslashreplace"written tosys.stdout.buffer— so unencodable characters degrade gracefully instead of crashing. Also
separates the decode and print steps and corrects a misleading
"Failed to encode" → "Failed to decode" log message.
Testing Guide
azdev test test_ssh_utils(covers the fallback, the printfast path, and end-to-end decode+output of emoji without disconnecting).
set PYTHONLEGACYWINDOWSSTDIO=1), run acontainer command that prints an emoji
(
az containerapp exec ... --command "printf '\xf0\x9f\xa6\x9e\n'"):crashes before this change, prints the character (or its
\U0001f99eescape)and keeps the session alive after.
History Notes
[Container App] Fix
az containerapp execcrash on non-ASCII (emoji) terminal output