Skip to content

Commit bb677bc

Browse files
authored
Capture ValidationException errors when deleting endpoints to not override previous exceptions (#14)
1 parent 191be47 commit bb677bc

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

tests/integ/timeout.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from contextlib import contextmanager
1515
import logging
1616

17+
from botocore.exceptions import ClientError
18+
1719
LOGGER = logging.getLogger('timeout')
1820

1921

@@ -59,8 +61,13 @@ def timeout_and_delete_endpoint(estimator, seconds=0, minutes=0, hours=0):
5961
try:
6062
yield [t]
6163
finally:
62-
estimator.delete_endpoint()
63-
LOGGER.info('deleted endpoint')
64+
try:
65+
estimator.delete_endpoint()
66+
LOGGER.info('deleted endpoint')
67+
except ClientError as ce:
68+
if ce.response['Error']['Code'] == 'ValidationException':
69+
# avoids the inner exception to be overwritten
70+
pass
6471

6572

6673
@contextmanager
@@ -69,5 +76,10 @@ def timeout_and_delete_endpoint_by_name(endpoint_name, sagemaker_session, second
6976
try:
7077
yield [t]
7178
finally:
72-
sagemaker_session.delete_endpoint(endpoint_name)
73-
LOGGER.info('deleted endpoint {}'.format(endpoint_name))
79+
try:
80+
sagemaker_session.delete_endpoint(endpoint_name)
81+
LOGGER.info('deleted endpoint {}'.format(endpoint_name))
82+
except ClientError as ce:
83+
if ce.response['Error']['Code'] == 'ValidationException':
84+
# avoids the inner exception to be overwritten
85+
pass

0 commit comments

Comments
 (0)