From ca8493ba58033f4efa8d95a54c006d9b03a6e94b Mon Sep 17 00:00:00 2001 From: nerfZael Date: Wed, 21 Feb 2024 20:16:24 +0100 Subject: [PATCH] improved error logging --- workers/fund_public_goods/events.py | 10 ++++++++-- .../fund_public_goods/lib/strategy/create.py | 17 +++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/workers/fund_public_goods/events.py b/workers/fund_public_goods/events.py index 010143b..acfadff 100644 --- a/workers/fund_public_goods/events.py +++ b/workers/fund_public_goods/events.py @@ -12,7 +12,7 @@ sys.modules['sqlite3'] = sys.modules.pop('pysqlite3') from dataclasses import dataclass -from typing import Any, Union +from typing import Any from aws_lambda_typing.events import SQSEvent from aws_lambda_typing.context import Context from fastapi_events.typing import Event as LocalEvent @@ -23,6 +23,7 @@ import os import json from fastapi import FastAPI +import logging @dataclass class EventData: @@ -33,7 +34,12 @@ def handler(event: EventData): if event.name == "create-strategy": run_id = event.payload["run_id"] authorization = event.payload["authorization"] - create(run_id, authorization) + + try: + create(run_id, authorization) + except Exception as error: + logging.exception(f"An error occurred while processing run_id: {run_id}") + raise error else: raise Exception("Unknown event name!") diff --git a/workers/fund_public_goods/lib/strategy/create.py b/workers/fund_public_goods/lib/strategy/create.py index 60a0522..7bbcd98 100644 --- a/workers/fund_public_goods/lib/strategy/create.py +++ b/workers/fund_public_goods/lib/strategy/create.py @@ -13,7 +13,6 @@ from fund_public_goods.lib.strategy.utils.summarize_descriptions import summarize_descriptions from supabase.lib.client_options import ClientOptions from fastapi import Header, HTTPException -from pydantic import BaseModel from typing import Optional, cast from langchain_community.callbacks import get_openai_callback @@ -64,14 +63,12 @@ def create(run_id: str, authorization: Optional[str] = Header(None)): value=f"Found {len(projects_with_answers)} projects related to '{prompt}'", ) except Exception as error: - details = error_details(error, run_id) tables.logs.update( status=StepStatus.ERRORED, log_id=log_ids[StepName.FETCH_PROJECTS], value=error_details(error, run_id) ) - print(error) - raise HTTPException(status_code=400, detail=details) + raise error try: tables.logs.update( @@ -109,14 +106,12 @@ def create(run_id: str, authorization: Optional[str] = Header(None)): value=f"Generated impact & funding needs reports for {len(projects_with_impact_funding_reports)} projects", ) except Exception as error: - details = error_details(error, run_id) tables.logs.update( status=StepStatus.ERRORED, log_id=log_ids[StepName.EVALUATE_PROJECTS], - value=details + value=error_details(error, run_id) ) - print(error) - raise HTTPException(status_code=400, detail=details) + raise error try: tables.logs.update( @@ -148,14 +143,12 @@ def create(run_id: str, authorization: Optional[str] = Header(None)): value=f"Computed smart rankings for {len(smart_ranked_projects)} projects", ) except Exception as error: - details = error_details(error, run_id) tables.logs.update( status=StepStatus.ERRORED, log_id=log_ids[StepName.ANALYZE_FUNDING], - value=details + value=error_details(error, run_id) ) - print(error) - raise HTTPException(status_code=400, detail=details) + raise error tables.logs.update(