Files
letta-server/letta/orm/errors.py
Kian Jones 0d42afa151 fix(core): catch LockNotAvailableError and return 409 instead of 500 (#9359)
Re-apply changes on top of latest main to resolve merge conflicts.

- Add DatabaseLockNotAvailableError custom exception in orm/errors.py
- Catch asyncpg LockNotAvailableError and pgcode 55P03 in _handle_dbapi_error
- Register FastAPI exception handler returning 409 with Retry-After header



🐾 Generated with [Letta Code](https://letta.com)

Co-authored-by: letta-code <248085862+letta-code@users.noreply.github.com>
Co-authored-by: Letta <noreply@letta.com>
2026-02-24 10:52:07 -08:00

39 lines
1.3 KiB
Python

class NoResultFound(Exception):
"""A record or records cannot be found given the provided search params"""
class MalformedIdError(Exception):
"""An id not in the right format, most likely violating uuid4 format."""
class UniqueConstraintViolationError(ValueError):
"""Custom exception for unique constraint violations."""
class ForeignKeyConstraintViolationError(ValueError):
"""Custom exception for foreign key constraint violations."""
class DatabaseLockNotAvailableError(Exception):
"""Raised when a database lock cannot be acquired (PostgreSQL 55P03)."""
def __init__(self, message="Could not acquire database lock", original_exception=None):
super().__init__(message)
self.original_exception = original_exception
class DatabaseTimeoutError(Exception):
"""Custom exception for database timeout issues."""
def __init__(self, message="Database operation timed out", original_exception=None):
super().__init__(message)
self.original_exception = original_exception
class DatabaseDeadlockError(Exception):
"""Custom exception for database deadlock errors (PostgreSQL error code 40P01)."""
def __init__(self, message="A database deadlock was detected", original_exception=None):
super().__init__(message)
self.original_exception = original_exception