Skip to content

az vm create: RuntimeError('already consumed') masks the real deployment error (SkuNotAvailable/QuotaExceeded) #34083

Open

Description

@robster7674

Describe the bug

When az vm create fails a deployment (e.g. SkuNotAvailable due to capacity restrictions, or QuotaExceeded), the CLI's own error-handling path throws a second, unrelated exception while trying to format the first one, so the top-level failure the user sees is a confusing internal traceback (RuntimeError: The content for this response was already consumed) instead of a clean error message. The real Azure error is still present deeper in the traceback text, but it's buried under CLI-internal noise.

Related command

az vm create \
  --resource-group <rg> \
  --name <vm> \
  --image Win2022Datacenter \
  --size Standard_B2s \
  --admin-username <user> \
  --admin-password <redacted> \
  --public-ip-address "" \
  --storage-sku StandardSSD_LRS

This reproduced consistently across multiple regions (westeurope, northeurope, eastus) and multiple VM sizes (Standard_B2s, Standard_B2ms, Standard_D2s_v3, Standard_D2s_v5, Standard_B1s) whenever the underlying deployment failed - both for SkuNotAvailable (capacity restriction) and QuotaExceeded failures.

Errors

Traceback (most recent call last):
  File "/opt/az/lib/python3.14/site-packages/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 "/opt/az/lib/python3.14/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
  File "/opt/az/lib/python3.14/site-packages/azure/cli/core/commands/__init__.py", line 677, in execute
    raise ex
  File "/opt/az/lib/python3.14/site-packages/azure/cli/core/commands/__init__.py", line 820, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/opt/az/lib/python3.14/site-packages/azure/cli/core/commands/__init__.py", line 812, in _run_job
    return cmd_copy.exception_handler(ex)
  File "/opt/az/lib/python3.14/site-packages/azure/cli/core/commands/arm.py", line 112, in handle_template_based_exception
    raise_subdivision_deployment_error(ex.response.internal_response.text, ex.error.code if ex.error else None)
  File "/opt/az/lib/python3.14/site-packages/requests/models.py", line 928, in text
    if not self.content:
  File "/opt/az/lib/python3.14/site-packages/requests/models.py", line 899, in content
    raise RuntimeError("The content for this response was already consumed")
RuntimeError: The content for this response was already consumed

The genuine deployment error (e.g.):

(SkuNotAvailable) The requested VM size for resource 'Following SKUs have failed for Capacity Restrictions: Standard_B2s' is currently not available in location 'eastus'. Please try another size or deploy to a different location or different zone.

or

Code: QuotaExceeded
Message: Operation could not be completed as it results in exceeding approved standardDSv5Family Cores quota. ... Current Limit: 0, Current Usage: 0, Additional Required: 2 ...

...is present in the exception text at that point, but raise_subdivision_deployment_error tries to read ex.response.internal_response.text a second time after requests has already consumed the stream, so formatting it throws RuntimeError instead of surfacing the message.

Expected behavior

A failed deployment (capacity, quota, or otherwise) should surface a single, clean error message from the actual Azure response - not a RuntimeError about an already-consumed HTTP response body masking it.

Environment summary

{
  "azure-cli": "2.89.1",
  "azure-cli-core": "2.89.1",
  "azure-cli-telemetry": "1.1.0"
}
  • OS: Linux (Ubuntu-based), Python 3.14
  • Reproduced with both Microsoft.Compute/virtualMachines classic az vm create deployments across three regions and five VM sizes.

Activity

  1. azure-client-tools-bot-prd commented on Sep 15, 2026

    @azure-client-tools-bot-prd

    Hi robster7674,

    2.89.1 is not the latest Azure CLI(2.90.0).

    If you haven't already attempted to do so, please upgrade to the latest Azure CLI version by following https://learn.microsoft.com/en-us/cli/azure/update-azure-cli.

  2. yonzhan commented on Sep 15, 2026

    @yonzhan
    Collaborator

    Thank you for opening this issue, we will look into it.

  3. added this to the Backlog milestone on Sep 15, 2026
  4. microsoft-github-policy-service commented on Sep 19, 2026

    @microsoft-github-policy-service
    Contributor

    🔔 Routing this issue to @Azure/act-observability-squad.

  5. x-engineering-agent commented on Sep 19, 2026

    @x-engineering-agent
    Contributor

    X Engineering Agent Bug Analysis

    Below is my analysis of this issue:

    Summary

    When an ARM-backed az vm create deployment fails, the reporter gets an unrelated RuntimeError about consumed HTTP content instead of the Azure deployment error. The BAMI sandbox reproduced this on Azure CLI 2.89.1, 2.91.0, and the current dev build with InvalidTemplateDeployment. Preserve the original service error so users can diagnose capacity or quota failures.

    Likely root cause

    The shared ARM template exception handler reads ex.inner_exception.error.message, then handles a missing inner_exception by reading ex.response.internal_response.text. For a streamed requests response whose uncached body was already consumed by the SDK, that read raises RuntimeError and replaces the original deployment error.

    Affected code
    • src/azure-cli-core/azure/cli/core/commands/arm.py › handle_template_based_exception (line 107)
    • src/azure-cli/azure/cli/command_modules/vm/commands.py › load_command_table (line 168)
    Ruled out
    • Configuration: An unavailable SKU or exceeded quota can explain the legitimate ARM failure, but cannot explain the secondary CLI RuntimeError while formatting that failure.
    • Environment: The reported Linux/Python 3.14 failure was also observed in the sandbox on Linux/Python 3.12, including the dev CLI build; it is not limited to the reporter installation.
    • Intended behavior: The handler was introduced to unwrap template deployment exceptions, not to replace an Azure service error with an HTTP stream exception.
    Proposed change

    Preserve the existing fix in PR #34238: in core/commands/arm.py handle_template_based_exception use the SDK-parsed HttpResponseError message when the inner exception is absent, without rereading consumed HTTP content; retain usable inner messages and InvalidTemplateDeployment classification. Refresh that PR with a live VM scenario covering the service error if it is missing.

    Origin
    • Introduced by: Add exception unwrapping for template-based creates. #6306 (commit 6a5f20c, 2018-05-08)
    • Original intent: Unwrap ARM template deployment exceptions to show the underlying Azure error instead of a generic deployment failure.
    • Does the fix keep that intent: Yes: use the SDK-parsed service error instead of rereading a consumed stream, retaining the existing CLI error classification.
    Why this surfaced now

    The handler lines predate the reports and have not materially changed since 2021; a specific SDK, requests, or service change triggering the observed stream state is unconfirmed. The 2026-03 requests and azure-core upgrades postdate earlier reports, so they cannot be the initial cause.

    Earlier related reports

    Blast radius
    • Other callers: 35 explicit handler registrations across vm (3), resource (25), network (4), and sqlvm (3); includes vm create, vmss create, deployment create/validate, VPN connection create, and sqlvm create.
    • Visible change for them: Those commands surface the Azure deployment error instead of a consumed-response RuntimeError when their SDK exception has no inner_exception.
    • Why not a narrower fix: A vm-only wrapper leaves the same shared handler vulnerable for ARM deployments in resource, network and sqlvm; change the handler while preserving its established error categories.
    Technical details

    Evidence

    • arm.py lines 107-114 read internal_response.text directly inside the AttributeError fallback.
    • vm/commands.py line 168 registers this handler for az vm create.
    • The sandbox run 39985582742 reached InvalidTemplateDeployment and the same consumed-content RuntimeError on reported, latest, and dev builds.

    Test plan

    Add a recorded vm/tests/latest ScenarioTest invoking az vm create against Azure with an unavailable VM size or zero-quota family so ARM returns an InvalidTemplateDeployment; assert the Azure error code and message survive without consumed-content RuntimeError. Record the test in the live-test lane, and rerun the same BAMI sandbox reproduction on the PR head. Complement it with SDK/requests unit tests for consumed streams, absent inner_exception, populated inner error, and non-SDK fallback; exercise deployment group validate as another caller of the shared handler.

    Generated code: Handwritten code. azure-cli-core/azure/cli/core/commands/arm.py is handwritten, outside the AAZ and AutoRest generated trees.

    Live reproduction (BAMI sandbox) — Reproduced

    Verdict: Reproduced on the current build.

    Version Result Evidence
    2.89.1 (reported) Reproduced InvalidTemplateDeployment, exit 1
    2.91.0 (latest) Reproduced InvalidTemplateDeployment, exit 1
    dev @ 0fb5754 Reproduced InvalidTemplateDeployment, exit 1
    Steps run (redacted)

    2.89.1 (reported)

    repro: az vm create --resource-group <rg> --name <name1> --image Win2022Datacenter --size Standard_B2s --admin-username agentuser --admin-password <password> --public-ip-address '' --storage-sku StandardSSD_LRS -> exit 1, InvalidTemplateDeployment, matches the issue
    

    2.91.0 (latest)

    repro: az vm create --resource-group <rg> --name <name1> --image Win2022Datacenter --size Standard_B2s --admin-username agentuser --admin-password <password> --public-ip-address '' --storage-sku StandardSSD_LRS -> exit 1, InvalidTemplateDeployment, matches the issue
    

    dev @ 0fb5754

    repro: az vm create --resource-group <rg> --name <name1> --image Win2022Datacenter --size Standard_B2s --admin-username agentuser --admin-password <password> --public-ip-address '' --storage-sku StandardSSD_LRS -> exit 1, InvalidTemplateDeployment, matches the issue
    

    Sandbox run

    Commands ran in an isolated Azure sandbox subscription from a validated ReproSpec; output is redacted.

    Posted by x-engineering-agent (Fixer)

  6. 12 remaining items

  7. added
    agent: reproducingThe Agent is reproducing this issue in a sandbox
    and removed
    agent: reproducingThe Agent is reproducing this issue in a sandbox
    on Oct 23, 2026
  8. added a commit that references this issue on Oct 24, 2026
    43512dc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Auto-AssignAuto assign by botAuto-ResolveAuto resolve by botAzure CLI TeamThe command of the issue is owned by Azure CLI teamComputeaz vm/vmss/image/disk/snapshotact-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