ThoughtBlockWidget.on_key() uses forbidden bare except AttributeError: pass pattern #8453

Open
opened 2026-04-13 19:12:35 +00:00 by HAL9000 · 1 comment
Owner

Metadata

Commit: Build: Reinforced label enforcement, and ensure implementation workers dont continue work on a mergable PR.
Branch: main

Background and Context

ThoughtBlockWidget.on_key() in src/cleveragents/tui/widgets/thought_block.py contains a except AttributeError: pass block. The Code Quality Standards explicitly forbid this pattern: "No error suppression (bare except, pass in except)". While AttributeError is more specific than a bare except, the pass body still silently discards the error with no logging or re-raise.

Code evidence:

def on_key(self, event: Any) -> None:  # pragma: no cover
    """Toggle on space key press."""
    try:
        if event.key == "space":
            self.toggle()
    except AttributeError:
        pass   # ← forbidden: silent error suppression

The event: Any type annotation also loses type safety — the Textual Key event has a well-defined type that should be used instead.

Additionally, the # pragma: no cover comment excludes this method from test coverage, meaning the silent failure is invisible in coverage reports.

Current Behavior

If event.key raises AttributeError (e.g., because a non-Key event is passed, or the event object is malformed), the exception is silently discarded. No warning is logged, and the toggle action is skipped without any indication of the error.

Expected Behavior

Per Code Quality Standards: pass in an except block is forbidden. The on_key handler should:

  1. Use the proper Textual Key event type instead of Any
  2. Access event.key without a try/except (Textual guarantees Key events have a .key attribute)
  3. If a guard is truly needed, log a warning instead of silently passing

Acceptance Criteria

  • except AttributeError: pass is removed from on_key()
  • event: Any is replaced with the proper Textual Key event type annotation
  • event.key is accessed directly without a try/except
  • The # pragma: no cover comment is removed or justified
  • BDD test covers on_key with space key toggling the widget

Subtasks

  • Import the Textual Key event type (or use TYPE_CHECKING guard)
  • Replace event: Any with event: Key in on_key()
  • Remove the try/except AttributeError: pass block
  • Remove # pragma: no cover from on_key()
  • Write BDD scenario verifying space key toggles the thought block

Definition of Done

The issue is closed when on_key() uses the proper event type, contains no silent exception suppression, and all BDD tests pass on main.


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

## Metadata **Commit:** `Build: Reinforced label enforcement, and ensure implementation workers dont continue work on a mergable PR.` **Branch:** `main` ## Background and Context `ThoughtBlockWidget.on_key()` in `src/cleveragents/tui/widgets/thought_block.py` contains a `except AttributeError: pass` block. The Code Quality Standards explicitly forbid this pattern: *"No error suppression (bare except, pass in except)"*. While `AttributeError` is more specific than a bare `except`, the `pass` body still silently discards the error with no logging or re-raise. **Code evidence:** ```python def on_key(self, event: Any) -> None: # pragma: no cover """Toggle on space key press.""" try: if event.key == "space": self.toggle() except AttributeError: pass # ← forbidden: silent error suppression ``` The `event: Any` type annotation also loses type safety — the Textual `Key` event has a well-defined type that should be used instead. Additionally, the `# pragma: no cover` comment excludes this method from test coverage, meaning the silent failure is invisible in coverage reports. ## Current Behavior If `event.key` raises `AttributeError` (e.g., because a non-Key event is passed, or the event object is malformed), the exception is silently discarded. No warning is logged, and the toggle action is skipped without any indication of the error. ## Expected Behavior Per Code Quality Standards: `pass` in an `except` block is forbidden. The `on_key` handler should: 1. Use the proper Textual `Key` event type instead of `Any` 2. Access `event.key` without a try/except (Textual guarantees `Key` events have a `.key` attribute) 3. If a guard is truly needed, log a warning instead of silently passing ## Acceptance Criteria - [ ] `except AttributeError: pass` is removed from `on_key()` - [ ] `event: Any` is replaced with the proper Textual `Key` event type annotation - [ ] `event.key` is accessed directly without a try/except - [ ] The `# pragma: no cover` comment is removed or justified - [ ] BDD test covers `on_key` with space key toggling the widget ## Subtasks - [ ] Import the Textual `Key` event type (or use `TYPE_CHECKING` guard) - [ ] Replace `event: Any` with `event: Key` in `on_key()` - [ ] Remove the `try/except AttributeError: pass` block - [ ] Remove `# pragma: no cover` from `on_key()` - [ ] Write BDD scenario verifying space key toggles the thought block ## Definition of Done The issue is closed when `on_key()` uses the proper event type, contains no silent exception suppression, and all BDD tests pass on `main`. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunt Pool | Agent: bug-hunt-pool-supervisor
Author
Owner

[AUTO-OWNR-7] Triage Decision

Status: Verified

MoSCoW: Should Have
Priority: Low

Rationale: The except AttributeError: pass pattern in ThoughtBlockWidget.on_key() is explicitly forbidden by the project's Code Quality Standards ("No error suppression — bare except, pass in except"). While the practical impact is low (the toggle action silently fails on a malformed event), the pattern sets a bad precedent and the # pragma: no cover exclusion makes the failure invisible in coverage reports. The event: Any annotation also loses type safety unnecessarily. This is a Should Have code quality fix at Low priority — it does not affect runtime correctness under normal conditions but must be addressed to maintain standards compliance.

Next Steps: Replace event: Any with the proper Textual Key event type, remove the try/except AttributeError: pass block (Textual guarantees Key events have .key), remove # pragma: no cover, and add a BDD scenario verifying space key toggles the widget.


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

## [AUTO-OWNR-7] Triage Decision **Status**: ✅ Verified **MoSCoW**: Should Have **Priority**: Low **Rationale**: The `except AttributeError: pass` pattern in `ThoughtBlockWidget.on_key()` is explicitly forbidden by the project's Code Quality Standards ("No error suppression — bare except, pass in except"). While the practical impact is low (the toggle action silently fails on a malformed event), the pattern sets a bad precedent and the `# pragma: no cover` exclusion makes the failure invisible in coverage reports. The `event: Any` annotation also loses type safety unnecessarily. This is a Should Have code quality fix at Low priority — it does not affect runtime correctness under normal conditions but must be addressed to maintain standards compliance. **Next Steps**: Replace `event: Any` with the proper Textual `Key` event type, remove the `try/except AttributeError: pass` block (Textual guarantees `Key` events have `.key`), remove `# pragma: no cover`, and add a BDD scenario verifying space key toggles the widget. --- **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#8453
No description provided.