Bug: Redundant Error Handling in CLI Commands #9041

Open
opened 2026-04-14 06:24:30 +00:00 by HAL9000 · 1 comment
Owner

Metadata

  • Commit Message: refactor(cli): remove redundant try/except blocks from CLI command handlers
  • Branch: refactor/cli-remove-redundant-error-handling

Background and Context

Multiple commands in the cleveragents.cli.commands module implement their own try...except blocks for error handling, which is redundant with the top-level error handler in cleveragents.cli.main.main. This duplicated code makes the error handling logic inconsistent and harder to maintain.

The top-level error handler in main() (lines 688–835 of src/cleveragents/cli/main.py) already catches:

  • SystemExit
  • typer.Exit
  • typer.Abort
  • CleverAgentsError
  • KeyboardInterrupt
  • Exception (catch-all)

Despite this, individual command files contain their own redundant try...except blocks that catch exceptions and re-raise them as typer.Exit or typer.Abort. For example:

  • src/cleveragents/cli/commands/project.py has 52 such occurrences
  • src/cleveragents/cli/commands/actor.py has 37 such occurrences
  • Other command files in src/cleveragents/cli/commands/ follow the same pattern

This violates the CONTRIBUTING.md principle: "Do not catch exceptions just to log and re-raise; let them propagate naturally." and "Only catch exceptions when you can meaningfully handle them."

Affected Files

  • src/cleveragents/cli/main.py
  • src/cleveragents/cli/commands/project.py
  • src/cleveragents/cli/commands/actor.py
  • Other command files in src/cleveragents/cli/commands/

Expected Behavior

Individual CLI commands should not implement their own error-handling try...except blocks for generic exception catching. They should let exceptions propagate up to the top-level error handler in main.py to ensure consistent, centralized error handling and reporting.

Exceptions should only be caught in command handlers when there is meaningful recovery logic (e.g., retry logic, resource cleanup, adding context). Generic catch-and-re-raise patterns must be removed.

Acceptance Criteria

  • All redundant try...except blocks in src/cleveragents/cli/commands/project.py that merely catch and re-raise as typer.Exit or typer.Abort without meaningful recovery logic are removed
  • All redundant try...except blocks in src/cleveragents/cli/commands/actor.py that merely catch and re-raise as typer.Exit or typer.Abort without meaningful recovery logic are removed
  • All other command files in src/cleveragents/cli/commands/ are audited and redundant error-handling blocks removed
  • The top-level error handler in src/cleveragents/cli/main.py remains the single authoritative error-handling point for CLI commands
  • All existing BDD scenarios continue to pass after the refactor
  • Test coverage remains >= 97%

Subtasks

  • Audit all files in src/cleveragents/cli/commands/ for redundant try...except blocks
  • Remove redundant try...except blocks from src/cleveragents/cli/commands/project.py
  • Remove redundant try...except blocks from src/cleveragents/cli/commands/actor.py
  • Remove redundant try...except blocks from remaining command files
  • Verify that meaningful exception handlers (with real recovery logic) are preserved
  • Tests (Behave): Add/update scenarios to verify error propagation reaches the top-level handler
  • Run nox -s unit_tests and fix any failures
  • Verify coverage >= 97% via nox -s coverage_report
  • Run nox (all default sessions), fix any errors

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly (refactor(cli): remove redundant try/except blocks from CLI command handlers), followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly (refactor/cli-remove-redundant-error-handling).
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.

Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata - **Commit Message**: `refactor(cli): remove redundant try/except blocks from CLI command handlers` - **Branch**: `refactor/cli-remove-redundant-error-handling` ## Background and Context Multiple commands in the `cleveragents.cli.commands` module implement their own `try...except` blocks for error handling, which is redundant with the top-level error handler in `cleveragents.cli.main.main`. This duplicated code makes the error handling logic inconsistent and harder to maintain. The top-level error handler in `main()` (lines 688–835 of `src/cleveragents/cli/main.py`) already catches: - `SystemExit` - `typer.Exit` - `typer.Abort` - `CleverAgentsError` - `KeyboardInterrupt` - `Exception` (catch-all) Despite this, individual command files contain their own redundant `try...except` blocks that catch exceptions and re-raise them as `typer.Exit` or `typer.Abort`. For example: - `src/cleveragents/cli/commands/project.py` has **52** such occurrences - `src/cleveragents/cli/commands/actor.py` has **37** such occurrences - Other command files in `src/cleveragents/cli/commands/` follow the same pattern This violates the CONTRIBUTING.md principle: *"Do not catch exceptions just to log and re-raise; let them propagate naturally."* and *"Only catch exceptions when you can meaningfully handle them."* ### Affected Files - `src/cleveragents/cli/main.py` - `src/cleveragents/cli/commands/project.py` - `src/cleveragents/cli/commands/actor.py` - Other command files in `src/cleveragents/cli/commands/` ## Expected Behavior Individual CLI commands should not implement their own error-handling `try...except` blocks for generic exception catching. They should let exceptions propagate up to the top-level error handler in `main.py` to ensure consistent, centralized error handling and reporting. Exceptions should only be caught in command handlers when there is **meaningful recovery logic** (e.g., retry logic, resource cleanup, adding context). Generic catch-and-re-raise patterns must be removed. ## Acceptance Criteria - [ ] All redundant `try...except` blocks in `src/cleveragents/cli/commands/project.py` that merely catch and re-raise as `typer.Exit` or `typer.Abort` without meaningful recovery logic are removed - [ ] All redundant `try...except` blocks in `src/cleveragents/cli/commands/actor.py` that merely catch and re-raise as `typer.Exit` or `typer.Abort` without meaningful recovery logic are removed - [ ] All other command files in `src/cleveragents/cli/commands/` are audited and redundant error-handling blocks removed - [ ] The top-level error handler in `src/cleveragents/cli/main.py` remains the single authoritative error-handling point for CLI commands - [ ] All existing BDD scenarios continue to pass after the refactor - [ ] Test coverage remains >= 97% ## Subtasks - [ ] Audit all files in `src/cleveragents/cli/commands/` for redundant `try...except` blocks - [ ] Remove redundant `try...except` blocks from `src/cleveragents/cli/commands/project.py` - [ ] Remove redundant `try...except` blocks from `src/cleveragents/cli/commands/actor.py` - [ ] Remove redundant `try...except` blocks from remaining command files - [ ] Verify that meaningful exception handlers (with real recovery logic) are preserved - [ ] Tests (Behave): Add/update scenarios to verify error propagation reaches the top-level handler - [ ] Run `nox -s unit_tests` and fix any failures - [ ] Verify coverage >= 97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions), fix any errors ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly (`refactor(cli): remove redundant try/except blocks from CLI command handlers`), followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly (`refactor/cli-remove-redundant-error-handling`). - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. --- **Automated by CleverAgents Bot** Agent: new-issue-creator
Author
Owner

Verified — Code quality: redundant error handling in CLI commands. MoSCoW: Should-have. Priority: Medium — code quality improvement.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

✅ **Verified** — Code quality: redundant error handling in CLI commands. MoSCoW: Should-have. Priority: Medium — code quality improvement. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
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#9041
No description provided.