diff --git a/sdk/core/azure-core/CHANGELOG.md b/sdk/core/azure-core/CHANGELOG.md index 6833621705b0..04cba3b0bc98 100644 --- a/sdk/core/azure-core/CHANGELOG.md +++ b/sdk/core/azure-core/CHANGELOG.md @@ -1,10 +1,10 @@ # Release History -## 1.24.0 (2022-05-05) +## 1.24.0 (2022-05-06) ### Features Added -- Add `SerializationError` and `DeserializationError` in `azure.core.serialization` for errors raised during serialization / deserialization #24113 +- Add `SerializationError` and `DeserializationError` in `azure.core.exceptions` for errors raised during serialization / deserialization #24312 ## 1.23.1 (2022-03-31) diff --git a/sdk/core/azure-core/azure/core/exceptions.py b/sdk/core/azure-core/azure/core/exceptions.py index 454135222174..00cf08abca8c 100644 --- a/sdk/core/azure-core/azure/core/exceptions.py +++ b/sdk/core/azure-core/azure/core/exceptions.py @@ -53,6 +53,8 @@ "StreamConsumedError", "StreamClosedError", "ResponseNotReadError", + "SerializationError", + "DeserializationError", ] @@ -494,3 +496,11 @@ def __init__(self, response): ) ) super(ResponseNotReadError, self).__init__(message) + +class SerializationError(ValueError): + """Raised if an error is encountered during serialization.""" + ... + +class DeserializationError(ValueError): + """Raised if an error is encountered during deserialization.""" + ... diff --git a/sdk/core/azure-core/azure/core/serialization.py b/sdk/core/azure-core/azure/core/serialization.py index 43be7e442835..4cb06d6437dc 100644 --- a/sdk/core/azure-core/azure/core/serialization.py +++ b/sdk/core/azure-core/azure/core/serialization.py @@ -11,7 +11,7 @@ from .utils._utils import _FixedOffset -__all__ = ["NULL", "AzureJSONEncoder", "SerializationError", "DeserializationError"] +__all__ = ["NULL", "AzureJSONEncoder"] class _Null(object): @@ -123,11 +123,3 @@ def default(self, o): # pylint: disable=too-many-return-statements except AttributeError: pass return super(AzureJSONEncoder, self).default(o) - -class SerializationError(ValueError): - """Raised if an error is encountered during serialization.""" - ... - -class DeserializationError(ValueError): - """Raised if an error is encountered during deserialization.""" - ... diff --git a/sdk/core/azure-core/tests/test_exceptions.py b/sdk/core/azure-core/tests/test_exceptions.py index 612225abb05b..970a7565b633 100644 --- a/sdk/core/azure-core/tests/test_exceptions.py +++ b/sdk/core/azure-core/tests/test_exceptions.py @@ -33,7 +33,7 @@ from mock import Mock # module under test -from azure.core.exceptions import HttpResponseError, ODataV4Error, ODataV4Format +from azure.core.exceptions import HttpResponseError, ODataV4Error, ODataV4Format, SerializationError, DeserializationError from azure.core.pipeline.transport import RequestsTransportResponse from azure.core.pipeline.transport._base import _HttpResponseBase as PipelineTransportHttpResponseBase from azure.core.rest._http_response_impl import _HttpResponseBaseImpl as RestHttpResponseBase @@ -320,3 +320,25 @@ def test_datav4_error(self, client, http_request): with pytest.raises(HttpResponseError) as ex: response.raise_for_status() assert "Content: {\"" not in str(ex.value) + +def test_serialization_error(): + message = "Oopsy bad input passed for serialization" + error = SerializationError(message) + with pytest.raises(SerializationError) as ex: + raise error + assert str(ex.value) == message + + with pytest.raises(ValueError) as ex: + raise error + assert str(ex.value) == message + +def test_deserialization_error(): + message = "Oopsy bad input passed for serialization" + error = DeserializationError(message) + with pytest.raises(DeserializationError) as ex: + raise error + assert str(ex.value) == message + + with pytest.raises(ValueError) as ex: + raise error + assert str(ex.value) == message diff --git a/sdk/core/azure-core/tests/test_serialization.py b/sdk/core/azure-core/tests/test_serialization.py index 0b5758fa6dcc..41f2914cf343 100644 --- a/sdk/core/azure-core/tests/test_serialization.py +++ b/sdk/core/azure-core/tests/test_serialization.py @@ -8,7 +8,7 @@ import json import sys -from azure.core.serialization import AzureJSONEncoder, NULL, SerializationError, DeserializationError +from azure.core.serialization import AzureJSONEncoder, NULL import pytest @@ -442,25 +442,3 @@ def __init__(self): ] } assert json.loads(json_dumps_with_encoder(expected.to_dict())) == expected_dict - -def test_serialization_error(): - message = "Oopsy bad input passed for serialization" - error = SerializationError(message) - with pytest.raises(SerializationError) as ex: - raise error - assert str(ex.value) == message - - with pytest.raises(ValueError) as ex: - raise error - assert str(ex.value) == message - -def test_deserialization_error(): - message = "Oopsy bad input passed for serialization" - error = DeserializationError(message) - with pytest.raises(DeserializationError) as ex: - raise error - assert str(ex.value) == message - - with pytest.raises(ValueError) as ex: - raise error - assert str(ex.value) == message