"""Exceptions module for lambdas.""" from src import status from constants import errors class LoggedException(Exception): """Exception to avoid propagation of general notification messages.""" def notify_and_raise( function, error_status, error_code, filename, bucket, error_params=None, input_params=None): """Send status notification and raise expection. Args: function (str): Lambda function name that causes an error. error_status (str): Error status for lambda function. error_code (str): Error code. filename (str): Current processed asset filename. bucket (str): Current processed asset source bucket name. error_params (dict): Additional error params. input_params (dict): Lambda additional input params for reporting. """ if not error_params: error_params = {} error_message = errors.ERROR_MESSAGES.get( error_code, 'Unknown Error').format(**error_params) status.send_general_status( function, error_status, filename, error_code, error_message, bucket, input_params) raise LoggedException(error_message)