Skip to content

Commit

Permalink
Merge pull request #223 from polywrap/nerfzael-error-logging
Browse files Browse the repository at this point in the history
Improved error logging
  • Loading branch information
cbrzn authored Feb 22, 2024
2 parents 243d549 + ca8493b commit a8fad8f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
10 changes: 8 additions & 2 deletions workers/fund_public_goods/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,6 +23,7 @@
import os
import json
from fastapi import FastAPI
import logging

@dataclass
class EventData:
Expand All @@ -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!")

Expand Down
17 changes: 5 additions & 12 deletions workers/fund_public_goods/lib/strategy/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

0 comments on commit a8fad8f

Please sign in to comment.