Refactor: Remove redundant DatabaseError wrapping in ToolRepository.add #8104

Open
opened 2026-04-13 03:33:37 +00:00 by HAL9000 · 0 comments
Owner

Metadata

  • Module: src/cleveragents/infrastructure/database/repositories.py
  • Lines: 3731-3732
  • Pass: Error Handling

Background and Context

The ToolRepository.add method is a wrapper around ToolRegistryRepository.create. The create method already handles SQLAlchemy exceptions and wraps them in a custom DatabaseError.

The add method in ToolRepository has its own try...except DatabaseError block that catches the DatabaseError raised by the create method and wraps it in another DatabaseError. This results in nested, redundant error messages (e.g., DatabaseError: Failed to add tool: DatabaseError: ...), which makes debugging more difficult.

Expected Behavior

The add method should not re-wrap DatabaseError exceptions. It should either let them propagate up or handle them more specifically. Removing the redundant except block would clean up the code and improve error clarity.

Acceptance Criteria

  • The redundant except DatabaseError block in ToolRepository.add is removed.
  • Error messages from the underlying create method are propagated without being re-wrapped.

Subtasks

  • Remove the except DatabaseError block from ToolRepository.add.
  • Verify that tests still pass and that database errors are correctly reported.

Definition of Done

  • The code is refactored as described.
  • The change is covered by unit tests.
  • The pull request is reviewed and merged.

Automated by CleverAgents Bot
Supervisor: Bug Hunt Pool | Agent: bug-hunt-pool-supervisor


Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata - **Module:** `src/cleveragents/infrastructure/database/repositories.py` - **Lines:** 3731-3732 - **Pass:** Error Handling ## Background and Context The `ToolRepository.add` method is a wrapper around `ToolRegistryRepository.create`. The `create` method already handles SQLAlchemy exceptions and wraps them in a custom `DatabaseError`. The `add` method in `ToolRepository` has its own `try...except DatabaseError` block that catches the `DatabaseError` raised by the `create` method and wraps it in another `DatabaseError`. This results in nested, redundant error messages (e.g., `DatabaseError: Failed to add tool: DatabaseError: ...`), which makes debugging more difficult. ## Expected Behavior The `add` method should not re-wrap `DatabaseError` exceptions. It should either let them propagate up or handle them more specifically. Removing the redundant `except` block would clean up the code and improve error clarity. ## Acceptance Criteria - The redundant `except DatabaseError` block in `ToolRepository.add` is removed. - Error messages from the underlying `create` method are propagated without being re-wrapped. ## Subtasks - [ ] Remove the `except DatabaseError` block from `ToolRepository.add`. - [ ] Verify that tests still pass and that database errors are correctly reported. ## Definition of Done - The code is refactored as described. - The change is covered by unit tests. - The pull request is reviewed and merged. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunt Pool | Agent: bug-hunt-pool-supervisor --- **Automated by CleverAgents Bot** Agent: new-issue-creator
HAL9000 added this to the v3.2.0 milestone 2026-04-13 03:33:40 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#8104
No description provided.