azure-cli: crash when handling InvalidTemplateDeployment (response already consumed)
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 3.5k
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 60
Description
Title: azure-cli: crash when handling InvalidTemplateDeployment (response already consumed)
Description:
When running `az vm create` the deployment fails with an ARM error (SkuNotAvailable). While handling the ARM template error the CLI hits an internal exception: "The content for this response was already consumed" which leads to an AttributeError and a RuntimeError. The CLI should surface the ARM inner error instead of crashing while trying to read the consumed response.
Environment:
- OS: macOS
- azure-cli: 2.84.0 (installed via Homebrew)
- Python: 3.13.12
- Command run:
```
az vm create --resource-group reliabilityLabRG1 --name vm1 --image Ubuntu2204 --admin-username azureuser --generate-ssh-keys
```
Relevant debug excerpt (tail of `~/az_vm_create_debug.log`):
```
Exception Details: (SkuNotAvailable) The requested VM size for resource 'Following SKUs have failed for Capacity Restrictions: Standard_DS1_v2' is currently not available in location 'eastus'. Please try another size or deploy to a different location or different zone.
Code: SkuNotAvailable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ".../azure/cli/core/commands/arm.py", line 109, in handle_template_based_exception
raise CLIError(ex.inner_exception.error.message)
^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'error'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ".../requests/models.py", line 926, in text
if not self.content:
^^^^^^^^^^^^
File ".../requests/models.py", line 897, in content
raise RuntimeError("The content for this response was already consumed")
RuntimeError: The content for this response was already consumed
```
What I expected:
- The CLI should show the ARM inner error (SkuNotAvailable) in a clear, non-failing way and not raise a secondary exception while formatting the message.
Steps to reproduce:
1. Ensure `eastus` subscription has capacity restrictions for `Standard_DS1_v2` (or simulate failure by requesting an unavailable SKU).
2. Run the `az vm create` command above.
3. Observe that the CLI crashes with a consumed response error while trying to display the template inner error.
Attachments / Logs:
- Full debug log saved at: `~/az_vm_create_debug.log` (tail included above)
- `az --version` output included in the debug log
Suggested fix:
- Guard against None `inner_exception` or already-consumed response when building CLI error messages; prefer to fall back to the HttpResponseError.message or the JSON body captured earlier.
Please let me know if you want the full `az_vm_create_debug.log` attached; I can paste it or provide a link.
Contributor guide
Assessment
This issue has not been assessed yet.