python-boto3/boto3/exceptions.py

127 lines
4 KiB
Python
Raw Permalink Normal View History

2015-11-27 23:25:33 +01:00
# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
2021-09-22 18:34:33 +02:00
# https://aws.amazon.com/apache2.0/
2015-11-27 23:25:33 +01:00
#
# or in the "license" file accompanying this file. This file is
# 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.
2016-05-22 04:03:29 +02:00
# All exceptions in this class should subclass from Boto3Error.
import botocore.exceptions
# All exceptions should subclass from Boto3Error in this module.
class Boto3Error(Exception):
"""Base class for all Boto3 errors."""
class ResourceLoadException(Boto3Error):
2015-11-27 23:25:33 +01:00
pass
2016-05-22 04:03:29 +02:00
# NOTE: This doesn't appear to be used anywhere.
# It's probably safe to remove this.
class NoVersionFound(Boto3Error):
2015-11-27 23:25:33 +01:00
pass
2016-05-22 04:03:29 +02:00
# We're subclassing from botocore.exceptions.DataNotFoundError
# to keep backwards compatibility with anyone that was catching
# this low level Botocore error before this exception was
# introduced in boto3.
# Same thing for ResourceNotExistsError below.
2022-05-26 01:13:54 +02:00
class UnknownAPIVersionError(
Boto3Error, botocore.exceptions.DataNotFoundError
):
def __init__(self, service_name, bad_api_version, available_api_versions):
2016-05-22 04:03:29 +02:00
msg = (
2022-05-26 01:13:54 +02:00
f"The '{service_name}' resource does not an API version of: {bad_api_version}\n"
f"Valid API versions are: {available_api_versions}"
2016-05-22 04:03:29 +02:00
)
# Not using super because we don't want the DataNotFoundError
# to be called, it has a different __init__ signature.
Boto3Error.__init__(self, msg)
2022-05-26 01:13:54 +02:00
class ResourceNotExistsError(
Boto3Error, botocore.exceptions.DataNotFoundError
):
2016-05-22 04:03:29 +02:00
"""Raised when you attempt to create a resource that does not exist."""
2022-05-26 01:13:54 +02:00
2016-05-22 04:03:29 +02:00
def __init__(self, service_name, available_services, has_low_level_client):
msg = (
2022-05-26 01:13:54 +02:00
"The '{}' resource does not exist.\n"
2016-05-22 04:03:29 +02:00
"The available resources are:\n"
2022-05-26 01:13:54 +02:00
" - {}\n".format(
service_name, '\n - '.join(available_services)
)
2016-05-22 04:03:29 +02:00
)
if has_low_level_client:
2022-05-26 01:13:54 +02:00
msg = (
f"{msg}\nConsider using a boto3.client('{service_name}') "
f"instead of a resource for '{service_name}'"
)
2016-05-22 04:03:29 +02:00
# Not using super because we don't want the DataNotFoundError
# to be called, it has a different __init__ signature.
Boto3Error.__init__(self, msg)
class RetriesExceededError(Boto3Error):
2015-11-27 23:25:33 +01:00
def __init__(self, last_exception, msg='Max Retries Exceeded'):
2022-05-26 01:13:54 +02:00
super().__init__(msg)
2015-11-27 23:25:33 +01:00
self.last_exception = last_exception
2016-05-22 04:03:29 +02:00
class S3TransferFailedError(Boto3Error):
2015-11-27 23:25:33 +01:00
pass
2016-05-22 04:03:29 +02:00
class S3UploadFailedError(Boto3Error):
2015-11-27 23:25:33 +01:00
pass
2016-05-22 04:03:29 +02:00
class DynamoDBOperationNotSupportedError(Boto3Error):
2021-09-22 18:34:33 +02:00
"""Raised for operations that are not supported for an operand."""
2022-05-26 01:13:54 +02:00
2015-11-27 23:25:33 +01:00
def __init__(self, operation, value):
msg = (
2022-05-26 01:13:54 +02:00
f'{operation} operation cannot be applied to value {value} of type '
f'{type(value)} directly. Must use AttributeBase object methods '
f'(i.e. Attr().eq()). to generate ConditionBase instances first.'
)
2015-11-27 23:25:33 +01:00
Exception.__init__(self, msg)
2021-09-22 18:34:33 +02:00
2015-11-27 23:25:33 +01:00
# FIXME: Backward compatibility
DynanmoDBOperationNotSupportedError = DynamoDBOperationNotSupportedError
2016-11-09 01:23:44 +01:00
2016-05-22 04:03:29 +02:00
class DynamoDBNeedsConditionError(Boto3Error):
2015-11-27 23:25:33 +01:00
"""Raised when input is not a condition"""
2022-05-26 01:13:54 +02:00
2015-11-27 23:25:33 +01:00
def __init__(self, value):
msg = (
2022-05-26 01:13:54 +02:00
f'Expecting a ConditionBase object. Got {value} of type {type(value)}. '
f'Use AttributeBase object methods (i.e. Attr().eq()). to '
f'generate ConditionBase instances.'
)
2015-11-27 23:25:33 +01:00
Exception.__init__(self, msg)
2016-05-22 04:03:29 +02:00
class DynamoDBNeedsKeyConditionError(Boto3Error):
2015-11-27 23:25:33 +01:00
pass
2021-09-22 18:34:33 +02:00
class PythonDeprecationWarning(Warning):
"""
Python version being used is scheduled to become unsupported
in an future release. See warning for specifics.
"""
2022-05-26 01:13:54 +02:00
2021-09-22 18:34:33 +02:00
pass