BUG-HUNT: [error-handling] Broad exception clause in _load_static_base in actor_selection_overlay.py #7938

Open
opened 2026-04-12 08:07:21 +00:00 by HAL9000 · 1 comment
Owner

Metadata

  • Branch: bugfix/m8-broad-exception-actor-selection-overlay
  • Commit Message: fix(tui): narrow broad except clause in _load_static_base to ImportError
  • Milestone: (none — backlog)
  • Parent Epic: #4963

Background and Context

The _load_static_base function in src/cleveragents/tui/widgets/actor_selection_overlay.py uses a broad except Exception: clause to handle the case where the optional textual dependency is not installed. This is bad practice as it can catch and hide unexpected errors, making debugging more difficult.

A similar issue exists in slash_command_overlay.py (tracked as #5953). This is a separate instance of the same anti-pattern in a different file.

Current Behavior

def _load_static_base() -> type[Any]:
    try:
        return importlib.import_module("textual.widgets").Static
    except Exception:  # pragma: no cover - optional dependency

        class _FallbackStatic:
            def __init__(self, *args: object, **kwargs: object) -> None:
                self._text = ""

            def update(self, text: str) -> None:
                self._text = text

        return _FallbackStatic

The except Exception: clause catches all exceptions, not just ImportError. If textual is installed but raises an unexpected exception (e.g., AttributeError, TypeError, ImportError from a transitive dependency), the error is silently swallowed and the fallback stub is returned instead, hiding the real problem.

Expected Behavior

The except clause should only catch ImportError, which is the specific exception raised when an optional dependency is not installed:

    except ImportError:  # pragma: no cover - optional dependency

Acceptance Criteria

  • _load_static_base in actor_selection_overlay.py uses except ImportError: instead of except Exception:
  • The # pragma: no cover - optional dependency comment is preserved
  • All nox stages pass
  • Coverage >= 97%

Subtasks

  • Replace except Exception: with except ImportError: in src/cleveragents/tui/widgets/actor_selection_overlay.py lines 19–29
  • Verify no other broad exception clauses exist in the same file
  • Run nox (all default sessions), fix any errors
  • Verify coverage >= 97% via nox -s coverage_report

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, 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.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.

Backlog note: This issue was discovered during autonomous operation
on milestone v3.7.0. It does not block milestone completion and has been
placed in the backlog for human review and future milestone assignment.


Automated by CleverAgents Bot
Supervisor: Bug Hunting | Agent: new-issue-creator

## Metadata - **Branch**: `bugfix/m8-broad-exception-actor-selection-overlay` - **Commit Message**: `fix(tui): narrow broad except clause in _load_static_base to ImportError` - **Milestone**: *(none — backlog)* - **Parent Epic**: #4963 ## Background and Context The `_load_static_base` function in `src/cleveragents/tui/widgets/actor_selection_overlay.py` uses a broad `except Exception:` clause to handle the case where the optional `textual` dependency is not installed. This is bad practice as it can catch and hide unexpected errors, making debugging more difficult. A similar issue exists in `slash_command_overlay.py` (tracked as #5953). This is a separate instance of the same anti-pattern in a different file. ## Current Behavior ```python def _load_static_base() -> type[Any]: try: return importlib.import_module("textual.widgets").Static except Exception: # pragma: no cover - optional dependency class _FallbackStatic: def __init__(self, *args: object, **kwargs: object) -> None: self._text = "" def update(self, text: str) -> None: self._text = text return _FallbackStatic ``` The `except Exception:` clause catches **all** exceptions, not just `ImportError`. If `textual` is installed but raises an unexpected exception (e.g., `AttributeError`, `TypeError`, `ImportError` from a transitive dependency), the error is silently swallowed and the fallback stub is returned instead, hiding the real problem. ## Expected Behavior The `except` clause should only catch `ImportError`, which is the specific exception raised when an optional dependency is not installed: ```python except ImportError: # pragma: no cover - optional dependency ``` ## Acceptance Criteria - [ ] `_load_static_base` in `actor_selection_overlay.py` uses `except ImportError:` instead of `except Exception:` - [ ] The `# pragma: no cover - optional dependency` comment is preserved - [ ] All nox stages pass - [ ] Coverage >= 97% ## Subtasks - [ ] Replace `except Exception:` with `except ImportError:` in `src/cleveragents/tui/widgets/actor_selection_overlay.py` lines 19–29 - [ ] Verify no other broad exception clauses exist in the same file - [ ] Run `nox` (all default sessions), fix any errors - [ ] Verify coverage >= 97% via `nox -s coverage_report` ## 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, 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. - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. > **Backlog note:** This issue was discovered during autonomous operation > on milestone v3.7.0. It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: new-issue-creator
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Backlog — TUI code quality issue; not blocking any milestone delivery
  • Milestone: v3.7.0 — TUI implementation milestone; this is a code quality fix for TUI code
  • Story Points: 2 — S — Simple one-line fix: replace except Exception: with except ImportError:
  • MoSCoW: Could Have — desirable code quality improvement but not blocking TUI functionality
  • Parent Epic: #4963 (EPIC: TUI Core Layout & Navigation, as noted in the issue)

Rationale: This is a valid code quality issue. The broad except Exception: clause in _load_static_base can hide unexpected errors. The fix is trivial (one line change). It's a "Could Have" because the current behavior (fallback stub) still works correctly for the common case.


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

Issue triaged by project owner: - **State**: Verified - **Priority**: Backlog — TUI code quality issue; not blocking any milestone delivery - **Milestone**: v3.7.0 — TUI implementation milestone; this is a code quality fix for TUI code - **Story Points**: 2 — S — Simple one-line fix: replace `except Exception:` with `except ImportError:` - **MoSCoW**: Could Have — desirable code quality improvement but not blocking TUI functionality - **Parent Epic**: #4963 (EPIC: TUI Core Layout & Navigation, as noted in the issue) **Rationale**: This is a valid code quality issue. The broad `except Exception:` clause in `_load_static_base` can hide unexpected errors. The fix is trivial (one line change). It's a "Could Have" because the current behavior (fallback stub) still works correctly for the common case. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
HAL9000 added this to the v3.7.0 milestone 2026-04-12 08:12:06 +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.

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