Azure / Azure/azure-cli

az vm create: SkuNotAvailable throws RuntimeError instead of clear error message

Open
#33,159 5 comments 0 reactions 1 assignee Assigned to @yanzhudd View on GitHub
act-observability-squad Auto-Assign Azure CLI Team Compute customer-reported Error Messages Possible-Solution question Similar-Issue squad squad:fixer
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

## Bug Report

### Description
When running `az vm create` with a VM size that is unavailable due to capacity restrictions, the CLI throws a confusing `RuntimeError: The content for this response was already consumed` instead of showing a clear, actionable error message.

The actual root cause (`SkuNotAvailable`) is buried deep in the traceback and not surfaced cleanly to the user.

---

### Command Used
```bash
az vm create \
-g rg-openclaw -n vm-openclaw \
--image Ubuntu2204 \
--size Standard_B2s \
--admin-username azureuser \
--generate-ssh-keys \
--vnet-name vnet-openclaw \
--subnet snet-openclaw-vm \
--location eastus
```

---

### Expected Behavior
A clean, user-friendly error message like:
```
ERROR: The VM size 'Standard_B2s' is not available in location 'eastus' due to capacity restrictions.
Suggestion: Try a different size or region. Run `az vm list-skus` to find available sizes.
```

### Actual Behavior
```
RuntimeError: The content for this response was already consumed
```
The real cause (`SkuNotAvailable: Standard_B2s not available in eastus/eastus2`) is only visible deep in the traceback.

---

### Impact
- Confusing for new Azure users
- No actionable suggestion is shown
- User has to read the full traceback to understand the real problem

---

### Environment
- Azure CLI version: latest (Azure Cloud Shell)
- OS: Linux (Azure Cloud Shell)
- Locations tested: `eastus`, `eastus2`
- VM size: `Standard_B2s`

---

### Suggested Fix
In `arm.py`, catch `SkuNotAvailable` inner exceptions and surface them as a clean `CLIError` with a helpful suggestion to run `az vm list-skus`.

---

### References
- Tracking ID: `4abe575f-76d8-4ae5-9ba1-a5ca05c7d169`
- Error code: `SkuNotAvailable`
- https://aka.ms/azureskunotavailable

### Related command

az vm create

### Errors

(InvalidTemplateDeployment) The template deployment is not valid according to the validation procedure.
Code: InvalidTemplateDeployment

Inner Error:
Code: SkuNotAvailable
Message: 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.

RuntimeError: The content for this response was already consumed

### Issue script & Debug output

az vm create \
-g rg-openclaw -n vm-openclaw \
--image Ubuntu2204 \
--size Standard_B2s \
--admin-username azureuser \
--generate-ssh-keys \
--vnet-name vnet-openclaw \
--subnet snet-openclaw-vm \
--debug

### Expected behavior

ERROR: The VM size 'Standard_B2s' is not available in location 'eastus'
due to capacity restrictions. Try a different size or region.
Tip: Run `az vm list-skus --location eastus --size Standard_B --output table`
to find available sizes.

### Environment Summary

az --version

### Additional context

Tested in both eastus and eastus2 — Standard_B2s unavailable in both
Error occurs in arm.py inside handle_template_based_exception where ex.inner_exception is None, causing an AttributeError that masks the real SkuNotAvailable error
Suggested fix: in arm.py, explicitly catch SkuNotAvailable from inner exceptions and raise a clean CLIError with a helpful suggestion
Reference: https://aka.ms/azureskunotavailable

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.