Skip to content
Open
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
6 changes: 6 additions & 0 deletions botocore/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,12 @@ def __init__(self, name, reason, last_response):
super().__init__(name=name, reason=reason)
self.last_response = last_response

def __reduce__(self):
return _exception_from_packed_args, (
self.__class__,
(self.kwargs['name'], self.kwargs['reason'], self.last_response),
)


class IncompleteReadError(BotoCoreError):
"""HTTP response did not return expected number of bytes."""
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import copy
import pickle

import botocore.awsrequest
Expand Down Expand Up @@ -167,3 +168,31 @@ def test_http_client_error(self):
self.assertIsInstance(
unpickled_exception.response, botocore.awsrequest.AWSResponse
)

def test_waiter_error(self):
exception = botocore.exceptions.WaiterError(
name='MyWaiter',
reason='MyReason',
last_response={'State': 'pending'},
)
unpickled_exception = pickle.loads(pickle.dumps(exception))
self.assertIsInstance(
unpickled_exception, botocore.exceptions.WaiterError
)
self.assertEqual(str(unpickled_exception), str(exception))
self.assertEqual(unpickled_exception.kwargs, exception.kwargs)
self.assertEqual(
unpickled_exception.last_response, exception.last_response
)

def test_waiter_error_can_be_copied(self):
exception = botocore.exceptions.WaiterError(
name='MyWaiter',
reason='MyReason',
last_response={'State': 'pending'},
)
copied_exception = copy.copy(exception)
self.assertIsInstance(copied_exception, botocore.exceptions.WaiterError)
self.assertEqual(str(copied_exception), str(exception))
self.assertEqual(copied_exception.kwargs, exception.kwargs)
self.assertEqual(copied_exception.last_response, exception.last_response)