CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-azure-mgmt-core

Azure management core library defines extensions to Azure Core that are specific to ARM (Azure Resource Management) needed when you use client libraries

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

exceptions.mddocs/

Exception Handling

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.

Capabilities

TypedErrorInfo

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: ...

Properties

  • type (str): The type of additional error information
  • info (Mapping[str, Any]): Detailed error information as key-value pairs

Usage Example

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"
# }

ARMErrorFormat

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: ...

Properties

  • additional_info (Sequence[TypedErrorInfo]): List of additional error information objects
  • Inherits all OData v4 format properties: code, message, target, details, innererror

Error Response Structure

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"
        }
      }
    ]
  }
}

Usage Example

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 information

Error Response Processing

When processing ARM error responses, the ARMErrorFormat automatically handles:

  1. Standard OData v4 Fields: Extracts code, message, target, details from the error object
  2. ARM Extensions: Processes additionalInfo array into TypedErrorInfo objects
  3. Nested Error Structure: Handles both direct error objects and error objects wrapped in "error" property

Common ARM Error Types

ARM operations may include these additional info types:

  • PolicyViolation: Policy assignment preventing the operation
  • QuotaExceeded: Resource quota limits reached
  • ResourceNotFound: Referenced resource doesn't exist
  • LocationNotAvailable: Requested region not available
  • SkuNotAvailable: Requested SKU not available in region
  • FeatureNotEnabled: Required feature not enabled for subscription

Integration with Azure Core

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}")

Key Features

OData v4 Compatibility

ARMErrorFormat maintains full compatibility with OData v4 error format while adding ARM-specific extensions. This ensures compatibility with existing Azure Core error handling patterns.

Structured Additional Information

Additional error information is parsed into structured TypedErrorInfo objects rather than raw dictionaries, providing type safety and consistent access patterns.

Flexible Error Parsing

Handles various ARM error response formats:

  • Responses with top-level "error" wrapper
  • Direct error objects without wrapper
  • Missing or empty additionalInfo arrays
  • Malformed additional info entries (gracefully ignored)

Rich String Representation

Both classes provide detailed string representations suitable for logging and debugging, including formatted JSON output for complex error information.

Types

# 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

docs

exceptions.md

index.md

pipeline-clients.md

policies.md

polling.md

resource-tools.md

tile.json