Skip to content

Commit

Permalink
Add more errors, make output writeable
Browse files Browse the repository at this point in the history
  • Loading branch information
vshia committed Sep 17, 2024
1 parent 656bb7e commit e0f5ff5
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions python/src/functions/generate_treasury_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down Expand Up @@ -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"}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e0f5ff5

Please sign in to comment.