BUG: [error-handling] Broad exception clause in _load_static_base in help_panel_overlay.py #7950

Open
opened 2026-04-12 08:22:55 +00:00 by HAL9000 · 3 comments
Owner

Metadata

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

Background and Context

The _load_static_base function in src/cleveragents/tui/widgets/help_panel_overlay.py uses a broad except Exception: clause to handle the case where the optional textual dependency is not installed. This is a recurring anti-pattern in the codebase (see also #7938 for the same issue in actor_selection_overlay.py) and is considered bad practice as it can catch and hide unexpected errors, making debugging more difficult.

Current Behavior

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

        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

Acceptance Criteria

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

Subtasks

  • Replace except Exception: with except ImportError: in src/cleveragents/tui/widgets/help_panel_overlay.py lines 9–21
  • 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

  • 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
  • All nox stages pass
  • Coverage >= 97%

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-help-panel-overlay` - **Commit Message**: `fix(tui): narrow broad except clause in _load_static_base to ImportError in help_panel_overlay` - **Milestone**: *(none — backlog)* - **Parent Epic**: #4963 ## Background and Context The `_load_static_base` function in `src/cleveragents/tui/widgets/help_panel_overlay.py` uses a broad `except Exception:` clause to handle the case where the optional `textual` dependency is not installed. This is a recurring anti-pattern in the codebase (see also #7938 for the same issue in `actor_selection_overlay.py`) and is considered bad practice as it can catch and hide unexpected errors, making debugging more difficult. ## Current Behavior ```python def _load_static_base() -> type[Any]: try: return importlib.import_module("textual.widgets").Static except Exception: # pragma: no cover 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 ``` ## Acceptance Criteria - [ ] `_load_static_base` in `help_panel_overlay.py` uses `except ImportError:` instead of `except Exception:` - [ ] The `# pragma: no cover` comment is preserved - [ ] All nox stages pass - [ ] Coverage >= 97% ## Subtasks - [ ] Replace `except Exception:` with `except ImportError:` in `src/cleveragents/tui/widgets/help_panel_overlay.py` lines 9–21 - [ ] 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 - [ ] 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 - [ ] All nox stages pass - [ ] Coverage >= 97% > **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

Verified — Code quality bug: broad exception clause in help_panel_overlay.py. MoSCoW: Should-have. Priority: Medium.


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

✅ **Verified** — Code quality bug: broad exception clause in help_panel_overlay.py. MoSCoW: Should-have. Priority: Medium. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Author
Owner

Verified — Code quality bug: broad exception clause in help_panel_overlay.py. MoSCoW: Should-have. Priority: Medium.


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

✅ **Verified** — Code quality bug: broad exception clause in help_panel_overlay.py. MoSCoW: Should-have. Priority: Medium. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Author
Owner

Verified — Code quality bug: broad exception clause in help_panel_overlay.py. MoSCoW: Should-have. Priority: Medium.


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

✅ **Verified** — Code quality bug: broad exception clause in help_panel_overlay.py. MoSCoW: Should-have. Priority: Medium. --- **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.

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