Source code for lambdas.s3_exceptions

import s3_status

default_detail_const = 'The object in the AWS event cannot be processed as a CSV file'
default_code_const = "Object cannot be read from S3"
#########################################################################################
# Batch Exceptions and Errors
#########################################################################################
[docs]class S3ProcessingException(Exception): """Base class for Exceptions due to S3 processing. Subclasses should provide `.status_code` and `.default_detail` properties. """ status_code = s3_status.EVENT_CANNOT_BE_PROCESSED default_detail = 'An error has occurred.' default_code = "Failed"
[docs] def __init__(self, detail=None, code=None): """ Args: detail: detailed message for the Exception to be initialised with code: error code the exception is to be initialised with """ if detail is None: detail = self.default_detail if code is None: code = self.default_code self.detail = detail self.code = code
[docs] def __str__(self): """ Returns: returns a string representation of the exception for printing. """ return str(self.detail)
[docs]class S3InputInvalidEventError(S3ProcessingException): """Error raised when the event cannot be parsed for s3 information.""" status_code = s3_status.EVENT_CANNOT_BE_PROCESSED default_detail = 'The event passed by AWS cannot be processed' default_code = "Event doesn't parse"
[docs]class S3InputNotPutEventError(S3ProcessingException): """Error raised when the event cannot be parsed for s3 information.""" status_code = s3_status.EVENT_CANNOT_BE_PROCESSED default_detail = 'The event passed by AWS cannot be processed' default_code = "Event doesn't parse"
[docs]class S3InputUnableToProcessError(S3ProcessingException): """Error raised when object within the event cannot be processed from S3 as a CSV.""" status_code = s3_status.OBJECT_CANNOT_BE_PROCESSED_AS_CSV default_detail = default_detail_const default_code = default_code_const
[docs]class S3InvalidSourceObjectNamesError(S3ProcessingException): """Error raised when trying to copy and object on S3 and the source attributes are incorrect/invalid.""" code = s3_status.INVALID_SOURCE_OBJECT_NAMES default_detail = default_detail_const default_code = default_code_const
[docs]class S3InvalidDestinationObjectNamesError(S3ProcessingException): """Error raised when trying to copy and object on S3 and the destination attributes are incorrect/invalid.""" status_code = s3_status.INVALID_DESTINATION_OBJECT_NAMES default_detail = default_detail_const default_code = default_code_const
[docs]class S3FailedToCopyError(S3ProcessingException): """Error raised when trying to copy and object on S3 and the destination attributes are incorrect/invalid.""" status_code = s3_status.FAILED_TO_COPY_OBJECT default_detail = 'Failed to Copy the object in S3' default_code = "Failed to Copy the object in S3"
[docs]class S3FailedToDeleteError(S3ProcessingException): """Error raised when trying to copy and object on S3 and the destination attributes are incorrect/invalid.""" status_code = s3_status.FAILED_TO_DELETE_OBJECT default_detail = 'Failed to Delete the object in S3' default_code = "Failed to Delete the object in S3"
[docs]class S3InvalidBucketError(S3ProcessingException): """Error raised when trying to copy and object on S3 and the destination attributes are incorrect/invalid.""" status_code = s3_status.S3_BUCKET_NAME_INVALID default_detail = 'Invalid bucket name passed to function' default_code = "Invalid bucket name passed to function"
[docs]class S3InvalidKeyError(S3ProcessingException): """Error raised when trying to copy and object on S3 and the destination attributes are incorrect/invalid.""" status_code = s3_status.S3_KEY_NAME_INVALID default_detail = 'Invalid key name passed to function' default_code = "Invalid key name passed to function"
[docs]class S3NoHeadersPassedError(S3ProcessingException): """Error raised when trying to copy and object on S3 and the destination attributes are incorrect/invalid.""" status_code = s3_status.S3_NO_HEADERS_PASSED_TO_WRITE default_detail = 'No headers were passed to the write function' default_code = "No headers were passed to the write function"
[docs]class S3NoListPassedError(S3ProcessingException): """Error raised when trying to copy and object on S3 and the destination attributes are incorrect/invalid.""" status_code = s3_status.S3_NO_ITEMS_PASSED_TO_WRITE default_detail = 'No items were passed to the write function' default_code = "No items were passed to the write function"
[docs]class S3CannotCreateCSVError(S3ProcessingException): """Error raised when trying to create the in-memory CSV file.""" status_code = s3_status.S3_CANNOT_WRITE_INMEMORY_CSV default_detail = 'An error occurred when trying to construct the in-memory CSV' default_code = "In-memory CSV error"
[docs]class S3CannotWriteCSVToS3Error(S3ProcessingException): """Error raised when trying to create the in-memory CSV file.""" status_code = s3_status.S3_CANNOT_PUT_CSV_TO_S3 default_detail = 'An error occurred when trying to write the CSV to S3' default_code = "Writing CSV error"