[Bug Hunt][Cycle 2][Config] Bare except clause masks critical errors in YAML import #7086

Open
opened 2026-04-10 07:33:34 +00:00 by HAL9000 · 1 comment
Owner

Background

The actor configuration module (src/cleveragents/actor/config.py) uses a bare except Exception: clause when importing PyYAML. This violates the project's error handling guidelines (CONTRIBUTING.md: "Do not suppress errors. Let exceptions propagate to top-level execution. Only catch exceptions when you can meaningfully handle them.") and can silently swallow critical system errors — making debugging nearly impossible and potentially causing undefined behavior.

Current Behavior

try:  # Optional dependency; present in dev/test extras
    import yaml
except Exception:  # pragma: no cover - defensive optional import
    yaml = None

All exceptions during yaml import are caught and silently ignored, including critical system errors (SyntaxError, SystemError, MemoryError, KeyboardInterrupt) that should terminate the program or propagate to the caller.

Expected Behavior

The code should only catch import-related exceptions (ImportError, ModuleNotFoundError), allowing all other critical exceptions to propagate properly:

try:
    import yaml
except (ImportError, ModuleNotFoundError):
    yaml = None

Acceptance Criteria

  • The bare except Exception: clause in src/cleveragents/actor/config.py lines 13–16 is replaced with except (ImportError, ModuleNotFoundError):
  • Critical exceptions (SyntaxError, SystemError, MemoryError, etc.) during yaml import propagate correctly and are not swallowed
  • A TDD issue-capture test (tagged @tdd_issue, @tdd_issue_<N>, @tdd_expected_fail) is created and merged before the fix is implemented
  • All nox stages pass after the fix
  • Coverage ≥ 97%

Supporting Information

  • File: src/cleveragents/actor/config.py
  • Lines: 13–16
  • Severity: Critical — silent failure during module import masks real system errors
  • Category: error-handling
  • Discovered during: Bug Hunt Cycle 2

TDD Note

Per the Bug Fix Workflow in CONTRIBUTING.md, a corresponding Type/Testing issue will be created with title TDD: [Bug Hunt][Cycle 2][Config] Bare except clause masks critical errors in YAML import. That TDD issue will deliver a test tagged @tdd_issue, @tdd_issue_<this-issue-number>, and @tdd_expected_fail. The original bug issue depends on the TDD issue via a Forgejo dependency link.


Metadata

  • Branch: bugfix/m3-config-bare-except-yaml-import
  • Commit Message: fix(actor/config): replace bare except with ImportError in yaml import
  • Milestone: v3.2.0
  • Parent Epic: #5502

Subtasks

  • Create TDD issue (Type/Testing) with @tdd_issue, @tdd_issue_<N>, @tdd_expected_fail tags
  • Link TDD issue as dependency (this bug issue depends on TDD issue)
  • Create tdd/m3-config-bare-except-yaml-import branch from master
  • Write Behave scenario in features/ proving the bare except swallows non-import errors
  • Merge TDD PR to master
  • Create bugfix/m3-config-bare-except-yaml-import branch from master
  • Replace except Exception: with except (ImportError, ModuleNotFoundError): in src/cleveragents/actor/config.py lines 13–16
  • Remove @tdd_expected_fail tag from TDD test (leave @tdd_issue and @tdd_issue_<N>)
  • Verify all nox stages pass
  • Verify coverage ≥ 97% via nox -s coverage_report
  • Open PR to master with Closes #<this-issue-number>

Definition of Done

  • except Exception: replaced with except (ImportError, ModuleNotFoundError): in src/cleveragents/actor/config.py
  • TDD test merged to master before fix branch is created
  • @tdd_expected_fail tag removed from TDD test; @tdd_issue and @tdd_issue_<N> remain
  • TDD test passes (assertion succeeds — bug is fixed)
  • All nox stages pass
  • Coverage >= 97%
  • PR reviewed and merged to master
  • This issue closed via Closes #<N> in the fix PR

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

## Background The actor configuration module (`src/cleveragents/actor/config.py`) uses a bare `except Exception:` clause when importing PyYAML. This violates the project's error handling guidelines (CONTRIBUTING.md: "Do not suppress errors. Let exceptions propagate to top-level execution. Only catch exceptions when you can meaningfully handle them.") and can silently swallow critical system errors — making debugging nearly impossible and potentially causing undefined behavior. ## Current Behavior ```python try: # Optional dependency; present in dev/test extras import yaml except Exception: # pragma: no cover - defensive optional import yaml = None ``` All exceptions during yaml import are caught and silently ignored, including critical system errors (`SyntaxError`, `SystemError`, `MemoryError`, `KeyboardInterrupt`) that should terminate the program or propagate to the caller. ## Expected Behavior The code should only catch import-related exceptions (`ImportError`, `ModuleNotFoundError`), allowing all other critical exceptions to propagate properly: ```python try: import yaml except (ImportError, ModuleNotFoundError): yaml = None ``` ## Acceptance Criteria - The bare `except Exception:` clause in `src/cleveragents/actor/config.py` lines 13–16 is replaced with `except (ImportError, ModuleNotFoundError):` - Critical exceptions (`SyntaxError`, `SystemError`, `MemoryError`, etc.) during yaml import propagate correctly and are not swallowed - A TDD issue-capture test (tagged `@tdd_issue`, `@tdd_issue_<N>`, `@tdd_expected_fail`) is created and merged before the fix is implemented - All nox stages pass after the fix - Coverage ≥ 97% ## Supporting Information - **File**: `src/cleveragents/actor/config.py` - **Lines**: 13–16 - **Severity**: Critical — silent failure during module import masks real system errors - **Category**: error-handling - **Discovered during**: Bug Hunt Cycle 2 ### TDD Note Per the Bug Fix Workflow in CONTRIBUTING.md, a corresponding `Type/Testing` issue will be created with title `TDD: [Bug Hunt][Cycle 2][Config] Bare except clause masks critical errors in YAML import`. That TDD issue will deliver a test tagged `@tdd_issue`, `@tdd_issue_<this-issue-number>`, and `@tdd_expected_fail`. The original bug issue **depends on** the TDD issue via a Forgejo dependency link. --- ## Metadata - **Branch**: `bugfix/m3-config-bare-except-yaml-import` - **Commit Message**: `fix(actor/config): replace bare except with ImportError in yaml import` - **Milestone**: v3.2.0 - **Parent Epic**: #5502 ## Subtasks - [ ] Create TDD issue (`Type/Testing`) with `@tdd_issue`, `@tdd_issue_<N>`, `@tdd_expected_fail` tags - [ ] Link TDD issue as dependency (this bug issue depends on TDD issue) - [ ] Create `tdd/m3-config-bare-except-yaml-import` branch from `master` - [ ] Write Behave scenario in `features/` proving the bare except swallows non-import errors - [ ] Merge TDD PR to `master` - [ ] Create `bugfix/m3-config-bare-except-yaml-import` branch from `master` - [ ] Replace `except Exception:` with `except (ImportError, ModuleNotFoundError):` in `src/cleveragents/actor/config.py` lines 13–16 - [ ] Remove `@tdd_expected_fail` tag from TDD test (leave `@tdd_issue` and `@tdd_issue_<N>`) - [ ] Verify all nox stages pass - [ ] Verify coverage ≥ 97% via `nox -s coverage_report` - [ ] Open PR to `master` with `Closes #<this-issue-number>` ## Definition of Done - [ ] `except Exception:` replaced with `except (ImportError, ModuleNotFoundError):` in `src/cleveragents/actor/config.py` - [ ] TDD test merged to `master` before fix branch is created - [ ] `@tdd_expected_fail` tag removed from TDD test; `@tdd_issue` and `@tdd_issue_<N>` remain - [ ] TDD test passes (assertion succeeds — bug is fixed) - [ ] All nox stages pass - [ ] Coverage >= 97% - [ ] PR reviewed and merged to `master` - [ ] This issue closed via `Closes #<N>` in the fix PR --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: new-issue-creator
HAL9000 added this to the v3.2.0 milestone 2026-04-10 07:33:38 +00:00
Author
Owner

Verified — Critical bug: bare except clause masks critical errors in YAML import. MoSCoW: Must-have. Priority: Critical.


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

✅ **Verified** — Critical bug: bare except clause masks critical errors in YAML import. MoSCoW: Must-have. Priority: Critical. --- **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#7086
No description provided.