Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk/core/azure-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Breaking Changes

- Sync stream downloading now raises `azure.core.exceptions.DecodeError` rather than `requests.exceptions.ContentDecodingError`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we okay with this breaking change because no one should have written code to explicitly handle this error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Checked with @johanste and he agreed this was an acceptable breaking change.


### Bugs Fixed

### Other Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import urllib3 # type: ignore
from urllib3.util.retry import Retry # type: ignore
from urllib3.exceptions import (
DecodeError, ReadTimeoutError, ProtocolError
DecodeError as CoreDecodeError, ReadTimeoutError, ProtocolError
)
import requests

Expand All @@ -39,6 +39,7 @@
ServiceResponseError,
IncompleteReadError,
HttpResponseError,
DecodeError
)
from . import HttpRequest # pylint: disable=unused-import

Expand Down Expand Up @@ -71,11 +72,11 @@ def _read_raw_stream(response, chunk_size=1):
for chunk in response.raw.stream(chunk_size, decode_content=False):
yield chunk
except ProtocolError as e:
raise requests.exceptions.ChunkedEncodingError(e)
except DecodeError as e:
raise requests.exceptions.ContentDecodingError(e)
raise ServiceResponseError(e, error=e)
except CoreDecodeError as e:
raise DecodeError(e, error=e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This scenario is being correctly handled in the other transports?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently different transport raises different type of error. (That's the reason we need this change).

We want to uniform the errors so user can catch all by using except AzureError.

except ReadTimeoutError as e:
raise requests.exceptions.ConnectionError(e)
raise ServiceRequestError(e, error=e)
else:
# Standard file-like object.
while True:
Expand Down Expand Up @@ -174,6 +175,8 @@ def __next__(self):
raise StopIteration()
except requests.exceptions.StreamConsumedError:
raise
except requests.exceptions.ContentDecodingError as err:
raise DecodeError(err, error=err)
except requests.exceptions.ChunkedEncodingError as err:
msg = err.__str__()
if 'IncompleteRead' in msg:
Expand Down
3 changes: 1 addition & 2 deletions sdk/core/azure-core/tests/test_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ def test_compress_compressed_no_header(http_request):
@pytest.mark.parametrize("http_request", HTTP_REQUESTS)
def test_decompress_plain_header(http_request):
# expect error
import requests
account_name = "coretests"
account_url = "https://{}.blob.core.windows.net".format(account_name)
url = "https://{}.blob.core.windows.net/tests/test_with_header.txt".format(account_name)
Expand All @@ -109,7 +108,7 @@ def test_decompress_plain_header(http_request):
try:
content = b"".join(list(data))
assert False
except (requests.exceptions.ContentDecodingError, DecodeError):
except DecodeError:
pass

@pytest.mark.parametrize("http_request", HTTP_REQUESTS)
Expand Down