diff --git a/python/src/functions/generate_treasury_report.py b/python/src/functions/generate_treasury_report.py index 151359a6..4b1df091 100644 --- a/python/src/functions/generate_treasury_report.py +++ b/python/src/functions/generate_treasury_report.py @@ -81,14 +81,14 @@ def handle(event: ProjectLambdaPayload, context: Context): try: payload = ProjectLambdaPayload.model_validate(event) - except Exception: - logger.exception("Exception parsing Project event payload") + except Exception as e: + logger.exception("Exception parsing Project event payload", e) return {"statusCode": 400, "body": "Bad Request"} try: process_event(payload, logger) - except Exception: - logger.exception("Exception processing Project file generation event") + except Exception as e: + logger.exception("Exception processing Project file generation event", e) return {"statusCode": 500, "body": "Internal Server Error"} return {"statusCode": 200, "body": "Success"} @@ -120,9 +120,9 @@ def process_event(payload: ProjectLambdaPayload, logger: structlog.stdlib.BoundL project_use_code = None try: project_use_code = ProjectType.from_project_name(payload.ProjectType) - except ValueError: + except ValueError as e: logger.error( - f"Project name '{payload.ProjectType}' is not a recognized project type." + f"Project name '{payload.ProjectType}' is not a recognized project type.", e ) return {"statusCode": 400, "body": "Invalid project name"} @@ -154,7 +154,7 @@ def process_event(payload: ProjectLambdaPayload, logger: structlog.stdlib.BoundL logger=logger, ) - output_workbook = load_workbook(filename=output_file, read_only=True) + output_workbook = load_workbook(filename=output_file, read_only=False) output_sheet = output_workbook["Baseline"] ### 3) Open files in the uploadsToRemove parameter. @@ -196,7 +196,7 @@ def process_event(payload: ProjectLambdaPayload, logger: structlog.stdlib.BoundL error = e.response.get("Error") or {} if error.get("Code") == "404": logger.exception( - f"Expected to find an upload with key: {file_info.objectKey}" + f"Expected to find an upload with key: {file_info.objectKey}", e ) raise # Load workbook @@ -283,7 +283,7 @@ def download_output_file( except ClientError as e: error = e.response.get("Error") or {} if error.get("Code") == "404": - logger.exception("Expected to find an existing treasury output report") + logger.exception("Expected to find an existing treasury output report", e) raise highest_row_num = max(project_agency_id_to_row_map.values()) else: @@ -322,7 +322,8 @@ def get_existing_output_metadata( error = e.response.get("Error") or {} if error.get("Code") == "404": logger.info( - "There is no existing metadata file for this treasury report" + "There is no existing metadata file for this treasury report", + e ) existing_file = None else: @@ -381,7 +382,8 @@ def get_outdated_projects_to_remove( error = e.response.get("Error") or {} if error.get("Code") == "404": logger.exception( - f"Expected to find an upload with key: {file_info.objectKey}" + f"Expected to find an upload with key: {file_info.objectKey}", + e ) raise # Load workbook