BUG-HUNT: [error-handling] Broad exception in TransformExecutor.execute #1932

Open
opened 2026-04-03 00:16:48 +00:00 by freemo · 2 comments
Owner

Metadata

  • Branch: fix/error-handling-transform-executor-execute
  • Commit Message: fix(tool): replace broad Exception catch in TransformExecutor.execute with specific exception types
  • Milestone: v3.2.0
  • Parent Epic: #1669

Bug Report: [error-handling] — Broad exception in TransformExecutor.execute

Severity Assessment

  • Impact: Potential to swallow and hide bugs, making debugging difficult.
  • Likelihood: Low, but possible if other unexpected errors occur.
  • Priority: Low

Location

  • File: src/cleveragents/tool/wrapping.py
  • Function/Class: TransformExecutor.execute

Description

The execute method in TransformExecutor uses a broad except Exception as exc: block. This can catch and obscure unexpected errors, making it difficult to debug issues that are not related to the transform function itself.

Evidence

        try:
            exec(  # nosec B102 # nosemgrep: no-exec
                self._compiled,
                sandbox,
            )
        except Exception as exc:
            raise TransformExecutionError(
                self._tool_name,
                f"Failed to compile/execute transform code: {exc}",
            ) from exc

Expected Behavior

The exception handling should be more specific, catching only the expected exceptions (e.g. SyntaxError, NameError, TypeError, RuntimeError). If the intention is to catch all exceptions, it should be logged and re-raised or handled in a way that doesn't hide the original error.

Suggested Fix

Catch more specific exceptions if possible. If not, log the exception and re-raise it or handle it in a way that preserves the original stack trace. Per CONTRIBUTING.md exception propagation guidelines: only catch exceptions when you can meaningfully handle them; otherwise let them propagate.

Category

error-handling

Subtasks

  • Write a TDD issue-capture Behave test that proves the bug exists (unexpected exceptions are silently wrapped into TransformExecutionError without any log trace)
  • Identify the concrete exception types that TransformExecutor.execute legitimately expects from exec() (e.g. SyntaxError, NameError, TypeError, RuntimeError)
  • Replace the single broad except Exception with targeted except clauses for each expected type
  • Add logger.exception (or exc_info=True) call for any truly unexpected exceptions so the full stack trace is always captured in structured logs
  • Ensure truly unexpected exceptions propagate or are wrapped in a domain-specific exception so callers are aware
  • Ensure all new code is fully statically typed and passes nox -e typecheck
  • Verify nox -e unit_tests passes with the new Behave scenario
  • Verify nox -e coverage_report reports coverage >= 97%

Definition of Done

  • A Behave scenario exists that captures the bug (fails before fix, passes after)
  • TransformExecutor.execute no longer silently wraps unexpected exceptions without logging
  • Full exception traceback is logged via structured logger on any unexpected failure
  • Only expected, well-understood exception types are caught without re-raising
  • Truly unexpected exceptions propagate (or are wrapped in a domain-specific exception) so callers are aware
  • No # type: ignore suppressions introduced
  • All nox stages pass
  • Coverage >= 97%

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

## Metadata - **Branch**: `fix/error-handling-transform-executor-execute` - **Commit Message**: `fix(tool): replace broad Exception catch in TransformExecutor.execute with specific exception types` - **Milestone**: v3.2.0 - **Parent Epic**: #1669 ## Bug Report: [error-handling] — Broad exception in TransformExecutor.execute ### Severity Assessment - **Impact**: Potential to swallow and hide bugs, making debugging difficult. - **Likelihood**: Low, but possible if other unexpected errors occur. - **Priority**: Low ### Location - **File**: `src/cleveragents/tool/wrapping.py` - **Function/Class**: `TransformExecutor.execute` ### Description The `execute` method in `TransformExecutor` uses a broad `except Exception as exc:` block. This can catch and obscure unexpected errors, making it difficult to debug issues that are not related to the transform function itself. ### Evidence ```python try: exec( # nosec B102 # nosemgrep: no-exec self._compiled, sandbox, ) except Exception as exc: raise TransformExecutionError( self._tool_name, f"Failed to compile/execute transform code: {exc}", ) from exc ``` ### Expected Behavior The exception handling should be more specific, catching only the expected exceptions (e.g. `SyntaxError`, `NameError`, `TypeError`, `RuntimeError`). If the intention is to catch all exceptions, it should be logged and re-raised or handled in a way that doesn't hide the original error. ### Suggested Fix Catch more specific exceptions if possible. If not, log the exception and re-raise it or handle it in a way that preserves the original stack trace. Per CONTRIBUTING.md exception propagation guidelines: only catch exceptions when you can meaningfully handle them; otherwise let them propagate. ### Category error-handling ## Subtasks - [ ] Write a TDD issue-capture Behave test that proves the bug exists (unexpected exceptions are silently wrapped into `TransformExecutionError` without any log trace) - [ ] Identify the concrete exception types that `TransformExecutor.execute` legitimately expects from `exec()` (e.g. `SyntaxError`, `NameError`, `TypeError`, `RuntimeError`) - [ ] Replace the single broad `except Exception` with targeted `except` clauses for each expected type - [ ] Add `logger.exception` (or `exc_info=True`) call for any truly unexpected exceptions so the full stack trace is always captured in structured logs - [ ] Ensure truly unexpected exceptions propagate or are wrapped in a domain-specific exception so callers are aware - [ ] Ensure all new code is fully statically typed and passes `nox -e typecheck` - [ ] Verify `nox -e unit_tests` passes with the new Behave scenario - [ ] Verify `nox -e coverage_report` reports coverage >= 97% ## Definition of Done - [ ] A Behave scenario exists that captures the bug (fails before fix, passes after) - [ ] `TransformExecutor.execute` no longer silently wraps unexpected exceptions without logging - [ ] Full exception traceback is logged via structured logger on any unexpected failure - [ ] Only expected, well-understood exception types are caught without re-raising - [ ] Truly unexpected exceptions propagate (or are wrapped in a domain-specific exception) so callers are aware - [ ] No `# type: ignore` suppressions introduced - [ ] All nox stages pass - [ ] Coverage >= 97% --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: ca-new-issue-creator
freemo added this to the v3.2.0 milestone 2026-04-03 00:16:58 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • MoSCoW: MoSCoW/Should Have — bug or error handling improvement.

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

Issue triaged by project owner: - **State**: Verified - **MoSCoW**: MoSCoW/Should Have — bug or error handling improvement. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
freemo removed this from the v3.2.0 milestone 2026-04-06 22:31:23 +00:00
Author
Owner

This issue has been moved to the backlog as part of an aggressive grooming of the v3.2.0 milestone. It has been deemed non-critical for the minimal viability of the milestone and will be addressed in a future release.

This issue has been moved to the backlog as part of an aggressive grooming of the v3.2.0 milestone. It has been deemed non-critical for the minimal viability of the milestone and will be addressed in a future release.
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.

Blocks
#1669 Bug Hunting Session
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#1932
No description provided.