Skip to content

Commit 9b839a1

Browse files
committed
Rename ServiceError to BaseError
Signed-off-by: Paul Van Eck <[email protected]>
1 parent 89abea1 commit 9b839a1

File tree

14 files changed

+73
-77
lines changed

14 files changed

+73
-77
lines changed

sdk/core/azure-core/azure/core/exceptions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from gencore.exceptions import (
4848
SerializationError,
4949
DeserializationError,
50-
ServiceError as AzureError,
50+
BaseError as AzureError,
5151
)
5252

5353
_LOGGER = logging.getLogger(__name__)

sdk/core/generic-core/gencore/exceptions.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646

4747
__all__ = [
48-
"ServiceError",
48+
"BaseError",
4949
"ServiceRequestError",
5050
"ServiceResponseError",
5151
"HttpResponseError",
@@ -124,7 +124,7 @@ def map_error(
124124
raise error
125125

126126

127-
class ServiceError(Exception):
127+
class BaseError(Exception):
128128
"""Base exception for all errors.
129129
130130
:param object message: The message object stringified as 'message' attribute
@@ -154,16 +154,16 @@ def __init__(self, message: Optional[object], *args: Any, **kwargs: Any) -> None
154154
self.exc_msg: str = "{}, {}: {}".format(message, self.exc_type.__name__, self.exc_value)
155155
self.message: str = str(message)
156156
self.continuation_token: Optional[str] = kwargs.get("continuation_token")
157-
super(ServiceError, self).__init__(self.message, *args)
157+
super(BaseError, self).__init__(self.message, *args)
158158

159159

160-
class ServiceRequestError(ServiceError):
160+
class ServiceRequestError(BaseError):
161161
"""An error occurred while attempt to make a request to the service.
162162
No request was sent.
163163
"""
164164

165165

166-
class ServiceResponseError(ServiceError):
166+
class ServiceResponseError(BaseError):
167167
"""The request was sent, but the client failed to understand the response.
168168
The connection may have timed out. These errors can be retried for idempotent or
169169
safe operations"""
@@ -177,7 +177,7 @@ class ServiceResponseTimeoutError(ServiceResponseError):
177177
"""Error raised when timeout happens"""
178178

179179

180-
class HttpResponseError(ServiceError):
180+
class HttpResponseError(BaseError):
181181
"""A request was made, and a non-success status code was received from the service.
182182
183183
:param object message: The message object stringified as 'message' attribute
@@ -253,7 +253,7 @@ class ResourceNotModifiedError(HttpResponseError):
253253
This will not be raised directly by the core pipeline."""
254254

255255

256-
class StreamConsumedError(ServiceError):
256+
class StreamConsumedError(BaseError):
257257
"""Error thrown if you try to access the stream of a response once consumed.
258258
259259
It is thrown if you try to read / stream an ~gencore.rest.HttpResponse or
@@ -271,7 +271,7 @@ def __init__(self, response: _HttpResponseCommonAPI) -> None:
271271
super(StreamConsumedError, self).__init__(message)
272272

273273

274-
class StreamClosedError(ServiceError):
274+
class StreamClosedError(BaseError):
275275
"""Error thrown if you try to access the stream of a response once closed.
276276
277277
It is thrown if you try to read / stream an ~gencore.rest.HttpResponse or
@@ -289,7 +289,7 @@ def __init__(self, response: _HttpResponseCommonAPI) -> None:
289289
super(StreamClosedError, self).__init__(message)
290290

291291

292-
class ResponseNotReadError(ServiceError):
292+
class ResponseNotReadError(BaseError):
293293
"""Error thrown if you try to access a response's content without reading first.
294294
295295
It is thrown if you try to access an ~gencore.rest.HttpResponse or

sdk/core/generic-core/gencore/paging.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
)
3939
import logging
4040

41-
from .exceptions import ServiceError
41+
from .exceptions import BaseError
4242

4343

4444
_LOGGER = logging.getLogger(__name__)
@@ -84,7 +84,7 @@ def __next__(self) -> Iterator[ReturnType]:
8484
raise StopIteration("End of paging")
8585
try:
8686
self._response = self._get_next(self.continuation_token)
87-
except ServiceError as error:
87+
except BaseError as error:
8888
if not error.continuation_token:
8989
error.continuation_token = self.continuation_token
9090
raise
@@ -181,7 +181,7 @@ async def __anext__(self) -> AsyncIterator[ReturnType]:
181181
raise StopAsyncIteration("End of paging")
182182
try:
183183
self._response = await self._get_next(self.continuation_token)
184-
except ServiceError as error:
184+
except BaseError as error:
185185
if not error.continuation_token:
186186
error.continuation_token = self.continuation_token
187187
raise

sdk/core/generic-core/gencore/runtime/policies/_retry.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from ...transport import HttpTransport
3434
from ...rest import HttpResponse, AsyncHttpResponse, HttpRequest
3535
from ...exceptions import (
36-
ServiceError,
36+
BaseError,
3737
ClientAuthenticationError,
3838
ServiceResponseError,
3939
ServiceRequestError,
@@ -152,7 +152,7 @@ def _is_connection_error(self, err: Exception) -> bool:
152152
request, so it should be safe to retry.
153153
154154
:param err: The error raised by the pipeline.
155-
:type err: ~gencore.exceptions.ServiceError
155+
:type err: ~gencore.exceptions.BaseError
156156
:return: True if connection error, False if not.
157157
:rtype: bool
158158
"""
@@ -163,7 +163,7 @@ def _is_read_error(self, err: Exception) -> bool:
163163
assume that the server began processing it.
164164
165165
:param err: The error raised by the pipeline.
166-
:type err: ~gencore.exceptions.ServiceError
166+
:type err: ~gencore.exceptions.BaseError
167167
:return: True if read error, False if not.
168168
:rtype: bool
169169
"""
@@ -258,7 +258,7 @@ def increment(
258258
:type response: ~gencore.runtime.pipeline.PipelineResponse
259259
:param error: An error encountered during the request, or
260260
None if the response was received successfully.
261-
:type error: ~gencore.exceptions.ServiceError
261+
:type error: ~gencore.exceptions.BaseError
262262
:return: Whether any retry attempt is available
263263
True if more retry attempts available, False otherwise
264264
:rtype: bool
@@ -484,7 +484,7 @@ def send(self, request: PipelineRequest[HttpRequest]) -> PipelineResponse[HttpRe
484484
:type request: ~gencore.runtime.pipeline.PipelineRequest
485485
:return: Returns the PipelineResponse or raises error if maximum retries exceeded.
486486
:rtype: ~gencore.runtime.pipeline.PipelineResponse
487-
:raises: ~gencore.exceptions.ServiceError if maximum retries exceeded.
487+
:raises: ~gencore.exceptions.BaseError if maximum retries exceeded.
488488
:raises: ~gencore.exceptions.ClientAuthenticationError if authentication
489489
"""
490490
retry_active = True
@@ -518,7 +518,7 @@ def send(self, request: PipelineRequest[HttpRequest]) -> PipelineResponse[HttpRe
518518
# the authentication policy failed such that the client's request can't
519519
# succeed--we'll never have a response to it, so propagate the exception
520520
raise
521-
except ServiceError as err:
521+
except BaseError as err:
522522
if absolute_timeout > 0 and self._is_method_retryable(retry_settings, request.http_request):
523523
retry_active = self.increment(retry_settings, response=request, error=err)
524524
if retry_active:
@@ -534,7 +534,7 @@ def send(self, request: PipelineRequest[HttpRequest]) -> PipelineResponse[HttpRe
534534
if absolute_timeout:
535535
absolute_timeout -= end_time - start_time
536536
if not response:
537-
raise ServiceError("Maximum retries exceeded.")
537+
raise BaseError("Maximum retries exceeded.")
538538

539539
self.update_context(response.context, retry_settings)
540540
return response

sdk/core/generic-core/gencore/runtime/policies/_retry_async.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from ...transport import AsyncHttpTransport
3535
from ...rest import AsyncHttpResponse, HttpRequest
3636
from ...exceptions import (
37-
ServiceError,
37+
BaseError,
3838
ClientAuthenticationError,
3939
ServiceRequestError,
4040
)
@@ -140,7 +140,7 @@ async def send(self, request: PipelineRequest[HttpRequest]) -> PipelineResponse[
140140
:type request: ~gencore.runtime.pipeline.PipelineRequest
141141
:return: Returns the PipelineResponse or raises error if maximum retries exceeded.
142142
:rtype: ~gencore.runtime.pipeline.PipelineResponse
143-
:raise: ~gencore.exceptions.ServiceError if maximum retries exceeded.
143+
:raise: ~gencore.exceptions.BaseError if maximum retries exceeded.
144144
:raise: ~gencore.exceptions.ClientAuthenticationError if authentication fails
145145
"""
146146
retry_active = True
@@ -178,7 +178,7 @@ async def send(self, request: PipelineRequest[HttpRequest]) -> PipelineResponse[
178178
# the authentication policy failed such that the client's request can't
179179
# succeed--we'll never have a response to it, so propagate the exception
180180
raise
181-
except ServiceError as err:
181+
except BaseError as err:
182182
if absolute_timeout > 0 and self._is_method_retryable(retry_settings, request.http_request):
183183
retry_active = self.increment(retry_settings, response=request, error=err)
184184
if retry_active:
@@ -194,7 +194,7 @@ async def send(self, request: PipelineRequest[HttpRequest]) -> PipelineResponse[
194194
if absolute_timeout:
195195
absolute_timeout -= end_time - start_time
196196
if not response:
197-
raise ServiceError("Maximum retries exceeded.")
197+
raise BaseError("Maximum retries exceeded.")
198198

199199
self.update_context(response.context, retry_settings)
200200
return response

sdk/core/generic-core/gencore/serialization.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313

1414
__all__ = ["NULL", "CoreJSONEncoder"]
15-
TZ_UTC = timezone.utc
1615

1716

1817
class _Null:
@@ -97,9 +96,9 @@ def _datetime_as_isostr(dt: Union[datetime, date, time, timedelta]) -> str:
9796
dt = cast(datetime, dt)
9897
# astimezone() fails for naive times in Python 2.7, so make make sure dt is aware (tzinfo is set)
9998
if not dt.tzinfo:
100-
iso_formatted = dt.replace(tzinfo=TZ_UTC).isoformat()
99+
iso_formatted = dt.replace(tzinfo=timezone.utc).isoformat()
101100
else:
102-
iso_formatted = dt.astimezone(TZ_UTC).isoformat()
101+
iso_formatted = dt.astimezone(timezone.utc).isoformat()
103102
# Replace the trailing "+00:00" UTC offset with "Z" (RFC 3339: https://www.ietf.org/rfc/rfc3339.txt)
104103
return iso_formatted.replace("+00:00", "Z")
105104
# Next try datetime.date or datetime.time

sdk/core/generic-core/gencore/transport/requests/_requests_basic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
if TYPE_CHECKING:
4848
from ...rest import HttpRequest as RestHttpRequest, HttpResponse as RestHttpResponse
4949

50-
ServiceErrorUnion = Union[
50+
BaseErrorUnion = Union[
5151
ServiceRequestError,
5252
ServiceResponseError,
5353
IncompleteReadError,
@@ -132,7 +132,7 @@ def send(self, request: "RestHttpRequest", **kwargs) -> "RestHttpResponse":
132132
"""
133133
self.open()
134134
response = None
135-
error: Optional[ServiceErrorUnion] = None
135+
error: Optional[BaseErrorUnion] = None
136136

137137
try:
138138
connection_timeout = kwargs.pop("connection_timeout", self.connection_config.get("timeout"))

sdk/core/generic-core/gencore/utils/_utils.py

-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@
1616
Union,
1717
Dict,
1818
)
19-
from datetime import timezone
2019
from urllib.parse import urlparse
2120

22-
TZ_UTC = timezone.utc
23-
2421

2522
class _FixedOffset(datetime.tzinfo):
2623
"""Fixed offset in minutes east from UTC.

sdk/core/generic-core/tests/async_tests/test_retry_policy_async.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import pytest
1919
from gencore.exceptions import (
20-
ServiceError,
20+
BaseError,
2121
ServiceRequestError,
2222
ServiceRequestTimeoutError,
2323
ServiceResponseError,
@@ -149,7 +149,7 @@ async def send(self, request: PipelineRequest, **kwargs: Any) -> PipelineRespons
149149
if self._first:
150150
self._first = False
151151
request.content.seek(0, 2)
152-
raise ServiceError("fail on first")
152+
raise BaseError("fail on first")
153153
position = request.content.tell()
154154
assert position == 0
155155
response = create_http_response(http_response, request, None, status_code=400)
@@ -185,7 +185,7 @@ async def send(self, request: PipelineRequest, **kwargs: Any) -> PipelineRespons
185185
name, body = value[0], value[1]
186186
if name and body and hasattr(body, "read"):
187187
body.seek(0, 2)
188-
raise ServiceError("fail on first")
188+
raise BaseError("fail on first")
189189
for value in request._files.values():
190190
name, body = value[0], value[1]
191191
if name and body and hasattr(body, "read"):

sdk/core/generic-core/tests/async_tests/test_streaming_async.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async def test_decompress_plain_no_header(http_request):
4040
client = AsyncPipelineClient(account_url)
4141
async with client:
4242
request = http_request("GET", url)
43-
pipeline_response = await client._pipeline.run(request, stream=True)
43+
pipeline_response = await client.pipeline.run(request, stream=True)
4444
response = pipeline_response.http_response
4545
data = response.iter_bytes()
4646
content = b""
@@ -60,7 +60,7 @@ async def test_compress_plain_no_header(http_request):
6060
client = AsyncPipelineClient(account_url)
6161
async with client:
6262
request = http_request("GET", url)
63-
pipeline_response = await client._pipeline.run(request, stream=True)
63+
pipeline_response = await client.pipeline.run(request, stream=True)
6464
response = pipeline_response.http_response
6565
data = response.iter_raw()
6666
content = b""
@@ -80,7 +80,7 @@ async def test_decompress_compressed_no_header(http_request):
8080
client = AsyncPipelineClient(account_url)
8181
async with client:
8282
request = http_request("GET", url)
83-
pipeline_response = await client._pipeline.run(request, stream=True)
83+
pipeline_response = await client.pipeline.run(request, stream=True)
8484
response = pipeline_response.http_response
8585
data = response.iter_bytes()
8686
content = b""
@@ -103,7 +103,7 @@ async def test_compress_compressed_no_header(http_request):
103103
client = AsyncPipelineClient(account_url)
104104
async with client:
105105
request = http_request("GET", url)
106-
pipeline_response = await client._pipeline.run(request, stream=True)
106+
pipeline_response = await client.pipeline.run(request, stream=True)
107107
response = pipeline_response.http_response
108108
data = response.iter_raw()
109109
content = b""
@@ -129,7 +129,7 @@ async def test_decompress_plain_header(http_request):
129129
client = AsyncPipelineClient(account_url)
130130
async with client:
131131
request = http_request("GET", url)
132-
pipeline_response = await client._pipeline.run(request, stream=True)
132+
pipeline_response = await client.pipeline.run(request, stream=True)
133133
response = pipeline_response.http_response
134134
data = response.iter_bytes()
135135
try:
@@ -151,7 +151,7 @@ async def test_compress_plain_header(http_request):
151151
client = AsyncPipelineClient(account_url)
152152
async with client:
153153
request = http_request("GET", url)
154-
pipeline_response = await client._pipeline.run(request, stream=True)
154+
pipeline_response = await client.pipeline.run(request, stream=True)
155155
response = pipeline_response.http_response
156156
data = response.iter_raw()
157157
content = b""
@@ -171,7 +171,7 @@ async def test_decompress_compressed_header(http_request):
171171
client = AsyncPipelineClient(account_url)
172172
async with client:
173173
request = http_request("GET", url)
174-
pipeline_response = await client._pipeline.run(request, stream=True)
174+
pipeline_response = await client.pipeline.run(request, stream=True)
175175
response = pipeline_response.http_response
176176
data = response.iter_bytes()
177177
content = b""
@@ -192,7 +192,7 @@ async def test_compress_compressed_header(http_request):
192192
client = AsyncPipelineClient(account_url)
193193
async with client:
194194
request = http_request("GET", url)
195-
pipeline_response = await client._pipeline.run(request, stream=True)
195+
pipeline_response = await client.pipeline.run(request, stream=True)
196196
response = pipeline_response.http_response
197197
data = response.iter_raw()
198198
content = b""

0 commit comments

Comments
 (0)