assertion error

This commit is contained in:
LeonOstrez
2024-12-13 10:31:15 +01:00
parent 542d121d1b
commit ca32893c17
2 changed files with 13 additions and 4 deletions

View File

@@ -10,6 +10,7 @@ from core.cli.helpers import delete_project, init, list_projects, list_projects_
from core.config import LLMProvider, get_config
from core.db.session import SessionManager
from core.db.v0importer import LegacyDatabaseImporter
from core.llm.anthropic_client import CustomAssertionError
from core.llm.base import APIError, BaseLLMClient
from core.log import get_logger
from core.state.state_manager import StateManager
@@ -67,6 +68,14 @@ async def run_project(sm: StateManager, ui: UIBase, args) -> bool:
)
telemetry.set("end_result", "failure:api-error")
await sm.rollback()
except CustomAssertionError as err:
log.warning(f"Anthropic assertion error occurred: {err.message}")
await ui.send_message(
f"Stopping Pythagora due to an error inside Anthropic SDK. {err.message}",
source=pythagora_source,
)
telemetry.set("end_result", "failure:assertion-error")
await sm.rollback()
except Exception as err:
log.error(f"Uncaught exception: {err}", exc_info=True)
stack_trace = telemetry.record_crash(err)

View File

@@ -19,7 +19,7 @@ MAX_TOKENS = 4096
MAX_TOKENS_SONNET = 8192
class RetryableError(Exception):
class CustomAssertionError(Exception):
pass
@@ -101,7 +101,7 @@ class AnthropicClient(BaseLLMClient):
final_message.content # Access content to verify it exists
except AssertionError:
log.debug("Anthropic package AssertionError")
raise RetryableError("Anthropic package AssertionError")
raise CustomAssertionError("No final message received.")
response_str = "".join(response)
@@ -114,9 +114,9 @@ class AnthropicClient(BaseLLMClient):
for attempt in range(retry_count + 1):
try:
return await single_attempt()
except RetryableError as e:
except CustomAssertionError as e:
if attempt == retry_count: # If this was our last attempt
raise RuntimeError(f"Request failed after {retry_count + 1} attempts: {str(e)}")
raise CustomAssertionError(f"Request failed after {retry_count + 1} attempts: {str(e)}")
# Add a small delay before retrying
await asyncio.sleep(1)
continue