Skip to content

Commit

Permalink
Revert changes to TypeError, ValueError, etc.
Browse files Browse the repository at this point in the history
Add a specific exception for service bus missing resource error, since that doesn't come back as an azure http error, but rather a parsing error.  For some reason service bus is happy to give you some results even when there are none.
  • Loading branch information
huguesv committed Jul 13, 2015
1 parent 1896238 commit dc37977
Show file tree
Hide file tree
Showing 30 changed files with 446 additions and 494 deletions.
18 changes: 3 additions & 15 deletions azure-common/azure/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class SubscriptionCloudCredentials(object):
"""
def __init__(self, subscription_id, access_token, access_token_type = 'Bearer'):
if access_token is None:
raise AzureValueError('access_token cannot be None.')
raise ValueError('access_token cannot be None.')

if subscription_id is None:
raise AzureValueError('subscription_id cannot be None.')
raise ValueError('subscription_id cannot be None.')

self._subscription_id = subscription_id
self._access_token = access_token
Expand Down Expand Up @@ -112,18 +112,6 @@ class AzureException(Exception):
pass


class AzureTypeError(AzureException, TypeError):
pass


class AzureIndexError(AzureException, IndexError):
pass


class AzureValueError(AzureException, ValueError):
pass


class AzureHttpError(AzureException):
def __init__(self, message, status_code):
super(AzureHttpError, self).__init__(message)
Expand Down Expand Up @@ -153,7 +141,7 @@ class Service(object):
"""
def __init__(self, credentials, **kwargs):
if credentials is None:
raise AzureValueError('credentials cannot be None.')
raise ValueError('credentials cannot be None.')

self._credentials = credentials
self._user_agent = kwargs.get('user_agent', azure.common.filters.DEFAULT_USER_AGENT)
Expand Down
184 changes: 92 additions & 92 deletions azure-mgmt-compute/azure/mgmt/compute/computemanagement.py

Large diffs are not rendered by default.

290 changes: 145 additions & 145 deletions azure-mgmt-network/azure/mgmt/network/networkresourceprovider.py

Large diffs are not rendered by default.

218 changes: 109 additions & 109 deletions azure-mgmt-resource/azure/mgmt/resource/resourcemanagement.py

Large diffs are not rendered by default.

88 changes: 44 additions & 44 deletions azure-mgmt-storage/azure/mgmt/storage/storagemanagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from urllib import quote, unquote
except:
from urllib.parse import quote, unquote
from azure.common import AzureOperationResponse, AzureHttpError, AzureIndexError, AzureValueError, OperationStatusResponse, OperationStatus, Service
from azure.common import AzureOperationResponse, AzureHttpError, OperationStatusResponse, OperationStatus, Service
from azure.common.arm import ResourceBase, ResourceBaseExtended

class StorageAccountCreateResponse(AzureOperationResponse):
Expand Down Expand Up @@ -727,7 +727,7 @@ def parse_account_type(self, value):
if 'Premium_LRS'.lower() == value.lower():
return AccountType.PremiumLRS

raise AzureIndexError('value is outside the valid range.')
raise IndexError('value is outside the valid range.')

def account_type_to_string(self, value):
"""
Expand Down Expand Up @@ -756,7 +756,7 @@ def account_type_to_string(self, value):
if value == AccountType.PremiumLRS:
return 'Premium_LRS'

raise AzureIndexError('value is outside the valid range.')
raise IndexError('value is outside the valid range.')

def parse_key_name(self, value):
"""
Expand All @@ -776,7 +776,7 @@ def parse_key_name(self, value):
if 'key2'.lower() == value.lower():
return KeyName.Key2

raise AzureIndexError('value is outside the valid range.')
raise IndexError('value is outside the valid range.')

def key_name_to_string(self, value):
"""
Expand All @@ -796,7 +796,7 @@ def key_name_to_string(self, value):
if value == KeyName.Key2:
return 'key2'

raise AzureIndexError('value is outside the valid range.')
raise IndexError('value is outside the valid range.')

def get_create_operation_status(self, operation_status_link):
"""
Expand All @@ -818,7 +818,7 @@ def get_create_operation_status(self, operation_status_link):
"""
# Validate
if operation_status_link is None:
raise AzureValueError('operation_status_link cannot be None.')
raise ValueError('operation_status_link cannot be None.')

# Tracing

Expand Down Expand Up @@ -1043,29 +1043,29 @@ def begin_create(self, resource_group_name, account_name, parameters):
"""
# Validate
if resource_group_name is None:
raise AzureValueError('resource_group_name cannot be None.')
raise ValueError('resource_group_name cannot be None.')

if account_name is None:
raise AzureValueError('account_name cannot be None.')
raise ValueError('account_name cannot be None.')

if len(account_name) < 3:
raise AzureIndexError('account_name is outside the valid range.')
raise IndexError('account_name is outside the valid range.')

if len(account_name) > 24:
raise AzureIndexError('account_name is outside the valid range.')
raise IndexError('account_name is outside the valid range.')

for account_name_char in account_name:
if account_name_char.islower() == False and account_name_char.isdigit() == False:
raise AzureIndexError('account_name is outside the valid range.')
raise IndexError('account_name is outside the valid range.')

if parameters is None:
raise AzureValueError('parameters cannot be None.')
raise ValueError('parameters cannot be None.')

if parameters.account_type is None:
raise AzureValueError('parameters.account_type cannot be None.')
raise ValueError('parameters.account_type cannot be None.')

if parameters.location is None:
raise AzureValueError('parameters.location cannot be None.')
raise ValueError('parameters.location cannot be None.')

# Tracing

Expand Down Expand Up @@ -1304,7 +1304,7 @@ def check_name_availability(self, account_name):
"""
# Validate
if account_name is None:
raise AzureValueError('account_name cannot be None.')
raise ValueError('account_name cannot be None.')

# Tracing

Expand Down Expand Up @@ -1467,20 +1467,20 @@ def delete(self, resource_group_name, account_name):
"""
# Validate
if resource_group_name is None:
raise AzureValueError('resource_group_name cannot be None.')
raise ValueError('resource_group_name cannot be None.')

if account_name is None:
raise AzureValueError('account_name cannot be None.')
raise ValueError('account_name cannot be None.')

if len(account_name) < 3:
raise AzureIndexError('account_name is outside the valid range.')
raise IndexError('account_name is outside the valid range.')

if len(account_name) > 24:
raise AzureIndexError('account_name is outside the valid range.')
raise IndexError('account_name is outside the valid range.')

for account_name_char in account_name:
if account_name_char.islower() == False and account_name_char.isdigit() == False:
raise AzureIndexError('account_name is outside the valid range.')
raise IndexError('account_name is outside the valid range.')

# Tracing

Expand Down Expand Up @@ -1557,20 +1557,20 @@ def get_properties(self, resource_group_name, account_name):
"""
# Validate
if resource_group_name is None:
raise AzureValueError('resource_group_name cannot be None.')
raise ValueError('resource_group_name cannot be None.')

if account_name is None:
raise AzureValueError('account_name cannot be None.')
raise ValueError('account_name cannot be None.')

if len(account_name) < 3:
raise AzureIndexError('account_name is outside the valid range.')
raise IndexError('account_name is outside the valid range.')

if len(account_name) > 24:
raise AzureIndexError('account_name is outside the valid range.')
raise IndexError('account_name is outside the valid range.')

for account_name_char in account_name:
if account_name_char.islower() == False and account_name_char.isdigit() == False:
raise AzureIndexError('account_name is outside the valid range.')
raise IndexError('account_name is outside the valid range.')

# Tracing

Expand Down Expand Up @@ -1982,7 +1982,7 @@ def list_by_resource_group(self, resource_group_name):
"""
# Validate
if resource_group_name is None:
raise AzureValueError('resource_group_name cannot be None.')
raise ValueError('resource_group_name cannot be None.')

# Tracing

Expand Down Expand Up @@ -2194,20 +2194,20 @@ def list_keys(self, resource_group_name, account_name):
"""
# Validate
if resource_group_name is None:
raise AzureValueError('resource_group_name cannot be None.')
raise ValueError('resource_group_name cannot be None.')

if account_name is None:
raise AzureValueError('account_name cannot be None.')
raise ValueError('account_name cannot be None.')

if len(account_name) < 3:
raise AzureIndexError('account_name is outside the valid range.')
raise IndexError('account_name is outside the valid range.')

if len(account_name) > 24:
raise AzureIndexError('account_name is outside the valid range.')
raise IndexError('account_name is outside the valid range.')

for account_name_char in account_name:
if account_name_char.islower() == False and account_name_char.isdigit() == False:
raise AzureIndexError('account_name is outside the valid range.')
raise IndexError('account_name is outside the valid range.')

# Tracing

Expand Down Expand Up @@ -2306,23 +2306,23 @@ def regenerate_key(self, resource_group_name, account_name, regenerate_key):
"""
# Validate
if resource_group_name is None:
raise AzureValueError('resource_group_name cannot be None.')
raise ValueError('resource_group_name cannot be None.')

if account_name is None:
raise AzureValueError('account_name cannot be None.')
raise ValueError('account_name cannot be None.')

if len(account_name) < 3:
raise AzureIndexError('account_name is outside the valid range.')
raise IndexError('account_name is outside the valid range.')

if len(account_name) > 24:
raise AzureIndexError('account_name is outside the valid range.')
raise IndexError('account_name is outside the valid range.')

for account_name_char in account_name:
if account_name_char.islower() == False and account_name_char.isdigit() == False:
raise AzureIndexError('account_name is outside the valid range.')
raise IndexError('account_name is outside the valid range.')

if regenerate_key is None:
raise AzureValueError('regenerate_key cannot be None.')
raise ValueError('regenerate_key cannot be None.')

# Tracing

Expand Down Expand Up @@ -2444,27 +2444,27 @@ def update(self, resource_group_name, account_name, parameters):
"""
# Validate
if resource_group_name is None:
raise AzureValueError('resource_group_name cannot be None.')
raise ValueError('resource_group_name cannot be None.')

if account_name is None:
raise AzureValueError('account_name cannot be None.')
raise ValueError('account_name cannot be None.')

if len(account_name) < 3:
raise AzureIndexError('account_name is outside the valid range.')
raise IndexError('account_name is outside the valid range.')

if len(account_name) > 24:
raise AzureIndexError('account_name is outside the valid range.')
raise IndexError('account_name is outside the valid range.')

for account_name_char in account_name:
if account_name_char.islower() == False and account_name_char.isdigit() == False:
raise AzureIndexError('account_name is outside the valid range.')
raise IndexError('account_name is outside the valid range.')

if parameters is None:
raise AzureValueError('parameters cannot be None.')
raise ValueError('parameters cannot be None.')

if parameters.custom_domain is not None:
if parameters.custom_domain.name is None:
raise AzureValueError('parameters.custom_domain.name cannot be None.')
raise ValueError('parameters.custom_domain.name cannot be None.')

# Tracing

Expand Down
1 change: 1 addition & 0 deletions azure-servicebus/azure/servicebus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from .models import (
AzureServiceBusPeekLockError,
AzureServiceBusResourceNotFound,
Queue,
Topic,
Subscription,
Expand Down
5 changes: 2 additions & 3 deletions azure-servicebus/azure/servicebus/_common_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
AzureHttpError,
AzureConflictHttpError,
AzureMissingResourceHttpError,
AzureTypeError,
)


Expand Down Expand Up @@ -68,9 +67,9 @@ def _dont_fail_not_exist(error):

def _validate_type_bytes(param_name, param):
if not isinstance(param, bytes):
raise AzureTypeError(_ERROR_VALUE_SHOULD_BE_BYTES.format(param_name))
raise TypeError(_ERROR_VALUE_SHOULD_BE_BYTES.format(param_name))


def _validate_not_none(param_name, param):
if param is None:
raise AzureTypeError(_ERROR_VALUE_NONE.format(param_name))
raise TypeError(_ERROR_VALUE_NONE.format(param_name))
5 changes: 1 addition & 4 deletions azure-servicebus/azure/servicebus/_common_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
except ImportError:
from xml.etree import ElementTree as ETree

from azure.common import (
AzureTypeError,
)
from ._common_conversion import (
_str,
)
Expand Down Expand Up @@ -175,7 +172,7 @@ def _get_request_body_bytes_only(param_name, param_value):
warnings.warn(_WARNING_VALUE_SHOULD_BE_BYTES.format(param_name))
return _get_request_body(param_value)

raise AzureTypeError(_ERROR_VALUE_SHOULD_BE_BYTES.format(param_name))
raise TypeError(_ERROR_VALUE_SHOULD_BE_BYTES.format(param_name))


def _get_request_body(request_body):
Expand Down
10 changes: 4 additions & 6 deletions azure-servicebus/azure/servicebus/_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
import sys

from datetime import datetime
from azure.common import (
AzureTypeError,
)
from .models import (
AzureServiceBusResourceNotFound,
Queue,
Topic,
Subscription,
Expand Down Expand Up @@ -245,7 +243,7 @@ def _convert_etree_element_to_queue(entry_element):
invalid_queue = False

if invalid_queue:
raise AzureTypeError(_ERROR_QUEUE_NOT_FOUND)
raise AzureServiceBusResourceNotFound(_ERROR_QUEUE_NOT_FOUND)

# extract id, updated and name value from feed entry and set them of queue.
for name, value in _ETreeXmlToObject.get_entry_properties_from_element(
Expand Down Expand Up @@ -298,7 +296,7 @@ def _convert_etree_element_to_topic(entry_element):
invalid_topic = False

if invalid_topic:
raise AzureTypeError(_ERROR_TOPIC_NOT_FOUND)
raise AzureServiceBusResourceNotFound(_ERROR_TOPIC_NOT_FOUND)

# extract id, updated and name value from feed entry and set them of topic.
for name, value in _ETreeXmlToObject.get_entry_properties_from_element(
Expand Down Expand Up @@ -414,7 +412,7 @@ def _convert_etree_element_to_event_hub(entry_element):
hub.authorization_rules.append(rule)

if invalid_event_hub:
raise AzureTypeError(_ERROR_EVENT_HUB_NOT_FOUND)
raise AzureServiceBusResourceNotFound(_ERROR_EVENT_HUB_NOT_FOUND)

# extract id, updated and name value from feed entry and set them of queue.
for name, value in _ETreeXmlToObject.get_entry_properties_from_element(
Expand Down
4 changes: 4 additions & 0 deletions azure-servicebus/azure/servicebus/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class AzureServiceBusPeekLockError(AzureException):
'''Indicates that peek-lock is required for this operation.'''


class AzureServiceBusResourceNotFound(AzureException):
'''Indicates that the resource doesn't exist.'''


class Queue(WindowsAzureData):

''' Queue class corresponding to Queue Description:
Expand Down
Loading

0 comments on commit dc37977

Please sign in to comment.