Skip to content

azure-cli: crash when handling InvalidTemplateDeployment (response already consumed) #32952

@EMMANUELOBINNAONYEMUCHE

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.

Metadata

Metadata

Assignees

Labels

Auto-AssignAuto assign by botComputeaz vm/vmss/image/disk/snapshotError MessagesPossible-SolutionService AttentionThis issue is responsible by Azure service team.Similar-Issueact-observability-squadcustomer-reportedIssues that are reported by GitHub users external to the Azure organization.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions