Azure management core library defines extensions to Azure Core that are specific to ARM (Azure Resource Management) needed when you use client libraries
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
ARM-specific error formatting and exception handling that extends Azure Core's OData v4 error format with additional ARM-specific error information. These classes provide enhanced error details for ARM operations.
Container for additional error information as defined in the ARM specification. Provides structured access to error type and detailed information.
class TypedErrorInfo:
"""Additional info class defined in ARM specification.
https://github.com/Azure/azure-resource-manager-rpc/blob/master/v1.0/common-api-details.md#error-response-content
"""
def __init__(self, type: str, info: Mapping[str, Any]) -> None: ...
def __str__(self) -> str: ...from azure.mgmt.core.exceptions import TypedErrorInfo
# Create typed error info
error_info = TypedErrorInfo(
type="PolicyViolation",
info={
"policyDefinitionId": "/subscriptions/.../policyDefinitions/allowed-locations",
"policyAssignmentId": "/subscriptions/.../policyAssignments/location-policy",
"policyEffect": "deny"
}
)
print(str(error_info))
# Output:
# Type: PolicyViolation
# Info: {
# "policyDefinitionId": "/subscriptions/.../policyDefinitions/allowed-locations",
# "policyAssignmentId": "/subscriptions/.../policyAssignments/location-policy",
# "policyEffect": "deny"
# }Enhanced error format for ARM operations that extends OData v4 error format with ARM-specific additional information. Provides comprehensive error details including policy violations, resource constraints, and other ARM-specific error contexts.
class ARMErrorFormat(ODataV4Format):
"""Describe error format from ARM, used at the base or inside "details" node.
This format is compatible with ODataV4 format.
https://github.com/Azure/azure-resource-manager-rpc/blob/master/v1.0/common-api-details.md#error-response-content
"""
def __init__(self, json_object: Mapping[str, Any]) -> None: ...
def __str__(self) -> str: ...ARM error responses follow this structure:
{
"error": {
"code": "InvalidParameter",
"message": "The parameter 'location' is invalid.",
"target": "location",
"details": [...],
"innererror": {...},
"additionalInfo": [
{
"type": "PolicyViolation",
"info": {
"policyDefinitionId": "...",
"policyAssignmentId": "...",
"policyEffect": "deny"
}
}
]
}
}import json
from azure.mgmt.core.exceptions import ARMErrorFormat
# Parse ARM error response
error_response = {
"error": {
"code": "InvalidLocation",
"message": "The location 'invalid-region' is not available for subscription.",
"target": "location",
"additionalInfo": [
{
"type": "PolicyViolation",
"info": {
"policyDefinitionId": "/subscriptions/.../policyDefinitions/allowed-locations",
"allowedLocations": ["eastus", "westus", "centralus"]
}
}
]
}
}
# Create ARM error format
arm_error = ARMErrorFormat(error_response)
print(arm_error.code) # "InvalidLocation"
print(arm_error.message) # "The location 'invalid-region' is not available for subscription."
print(arm_error.target) # "location"
# Access additional info
for info in arm_error.additional_info:
print(f"Type: {info.type}")
print(f"Info: {info.info}")
print(str(arm_error))
# Output includes both OData v4 format and additional ARM-specific informationWhen processing ARM error responses, the ARMErrorFormat automatically handles:
ARM operations may include these additional info types:
ARMErrorFormat extends Azure Core's ODataV4Format, providing seamless integration:
from azure.core.exceptions import HttpResponseError
from azure.mgmt.core.exceptions import ARMErrorFormat
# Typically used in Azure SDK exception handling
try:
# ARM operation that may fail
result = client.some_arm_operation()
except HttpResponseError as e:
# Parse ARM-specific error details
if e.response.status_code >= 400:
arm_error = ARMErrorFormat(e.response.json())
print(f"ARM Error: {arm_error.code}")
print(f"Message: {arm_error.message}")
# Handle additional ARM-specific info
for info in arm_error.additional_info:
if info.type == "PolicyViolation":
print(f"Policy blocked operation: {info.info}")
elif info.type == "QuotaExceeded":
print(f"Quota exceeded: {info.info}")ARMErrorFormat maintains full compatibility with OData v4 error format while adding ARM-specific extensions. This ensures compatibility with existing Azure Core error handling patterns.
Additional error information is parsed into structured TypedErrorInfo objects rather than raw dictionaries, providing type safety and consistent access patterns.
Handles various ARM error response formats:
Both classes provide detailed string representations suitable for logging and debugging, including formatted JSON output for complex error information.
# Type hints for error handling
from typing import Mapping, Any, Sequence
# Used in TypedErrorInfo
InfoMapping = Mapping[str, Any]
# Used in ARMErrorFormat
JsonObject = Mapping[str, Any]Install with Tessl CLI
npx tessl i tessl/pypi-azure-mgmt-core