Skip to content

Commit

Permalink
[ServiceBus] mode (ReceiveMode) parameter needs better exception beha…
Browse files Browse the repository at this point in the history
…vior (#13531)

* mode parameter needs better exception behavior, as if it is mis-typed now it will return an AttributeError further down the stack without useful guidance (and only does so when creating the handler, as well).  Will now return a TypeError at initialization.
* Add note of AttributeError->TypeError behavior for receive_mode misalignment to changelog.
  • Loading branch information
KieranBrantnerMagee authored Sep 21, 2020
1 parent db635d2 commit ad2142b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions sdk/servicebus/azure-servicebus/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 7.0.0b7 (Unreleased)

**Breaking Changes**
* Passing any type other than `ReceiveMode` as parameter `receive_mode` now throws a `TypeError` instead of `AttributeError`.

## 7.0.0b6 (2020-09-10)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def _populate_attributes(self, **kwargs):
self._auth_uri = "sb://{}/{}".format(self.fully_qualified_namespace, self.entity_path)
self._entity_uri = "amqps://{}/{}".format(self.fully_qualified_namespace, self.entity_path)
self._receive_mode = kwargs.get("receive_mode", ReceiveMode.PeekLock)
# While we try to leave failures to the service, in this case the errors lower down the stack are less clear.
if not isinstance(self._receive_mode, ReceiveMode):
raise TypeError("Parameter 'receive_mode' must be of type ReceiveMode")

self._error_policy = _ServiceBusErrorPolicy(
max_retries=self._config.retry_total
)
Expand Down
11 changes: 6 additions & 5 deletions sdk/servicebus/azure-servicebus/tests/test_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -1857,11 +1857,12 @@ def test_queue_receiver_invalid_mode(self, servicebus_namespace_connection_strin

with ServiceBusClient.from_connection_string(
servicebus_namespace_connection_string, logging_enable=False) as sb_client:
# with pytest.raises(StopIteration):
with sb_client.get_queue_receiver(servicebus_queue.name,
max_wait_time="oij") as receiver:

assert receiver
with pytest.raises(TypeError):
with sb_client.get_queue_receiver(servicebus_queue.name,
receive_mode=2) as receiver:

raise Exception("Should not get here, should fail fast.")


@pytest.mark.liveTest
@pytest.mark.live_test_only
Expand Down

0 comments on commit ad2142b

Please sign in to comment.