BUG: [error-handling] Exception during migration prompt is not logged #1274

Open
opened 2026-04-02 08:19:53 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: fix/error-handling-migration-runner-prompt-exception-logging
  • Commit Message: fix(error-handling): log exception in MigrationRunner._default_prompt_for_migration
  • Milestone: v3.3.0
  • Parent Epic: #362

Background

The _default_prompt_for_migration method in MigrationRunner catches a broad except Exception: when the interactive prompt fails, but does not include the caught exception in the debug log message. This violates the project's error-handling standards (CONTRIBUTING.md: "Errors must not be suppressed") and makes it impossible to diagnose why the interactive prompt failed in non-standard environments.

When the exception is swallowed silently, the function silently falls through to auto-approving the migration — which may not be the desired behaviour and cannot be investigated without the exception detail.

Location

  • File: src/cleveragents/infrastructure/database/migration_runner.py
  • Function: MigrationRunner._default_prompt_for_migration
  • Lines: 364–368

Evidence

# Current (broken) code
except Exception:
    # Fall through to auto-approval below if prompting fails
    logging.getLogger(__name__).debug(
        "Interactive prompt failed, auto-approving migrations"
    )

Expected Behaviour

The caught exception should be included in the debug log message so developers can understand why the interactive prompt failed.

Suggested Fix

except Exception as e:
    # Fall through to auto-approval below if prompting fails
    logging.getLogger(__name__).debug(
        "Interactive prompt failed, auto-approving migrations: %s", e
    )

Subtasks

  • Write a TDD issue-capture Behave scenario (tagged @tdd_expected_fail) that asserts the exception is present in the debug log output when the prompt raises
  • Bind the caught exception to e in the except clause
  • Pass e as a formatting argument to the existing debug(...) call
  • Remove the @tdd_expected_fail tag once the fix is in place and the scenario passes
  • Confirm all nox sessions pass (nox -e lint, nox -e typecheck, nox -e unit_tests, nox -e coverage_report)

Definition of Done

  • TDD issue-capture scenario exists and initially fails (demonstrating the bug)
  • Fix is applied: exception is bound and logged in the debug message
  • TDD scenario now passes with the fix in place
  • No regressions in existing MigrationRunner test scenarios
  • All nox stages pass
  • Coverage >= 97%
## Metadata - **Branch**: `fix/error-handling-migration-runner-prompt-exception-logging` - **Commit Message**: `fix(error-handling): log exception in MigrationRunner._default_prompt_for_migration` - **Milestone**: v3.3.0 - **Parent Epic**: #362 ## Background The `_default_prompt_for_migration` method in `MigrationRunner` catches a broad `except Exception:` when the interactive prompt fails, but does not include the caught exception in the debug log message. This violates the project's error-handling standards (CONTRIBUTING.md: *"Errors must not be suppressed"*) and makes it impossible to diagnose why the interactive prompt failed in non-standard environments. When the exception is swallowed silently, the function silently falls through to auto-approving the migration — which may not be the desired behaviour and cannot be investigated without the exception detail. ### Location - **File**: `src/cleveragents/infrastructure/database/migration_runner.py` - **Function**: `MigrationRunner._default_prompt_for_migration` - **Lines**: 364–368 ### Evidence ```python # Current (broken) code except Exception: # Fall through to auto-approval below if prompting fails logging.getLogger(__name__).debug( "Interactive prompt failed, auto-approving migrations" ) ``` ### Expected Behaviour The caught exception should be included in the debug log message so developers can understand why the interactive prompt failed. ### Suggested Fix ```python except Exception as e: # Fall through to auto-approval below if prompting fails logging.getLogger(__name__).debug( "Interactive prompt failed, auto-approving migrations: %s", e ) ``` ## Subtasks - [ ] Write a TDD issue-capture Behave scenario (tagged `@tdd_expected_fail`) that asserts the exception is present in the debug log output when the prompt raises - [ ] Bind the caught exception to `e` in the `except` clause - [ ] Pass `e` as a formatting argument to the existing `debug(...)` call - [ ] Remove the `@tdd_expected_fail` tag once the fix is in place and the scenario passes - [ ] Confirm all nox sessions pass (`nox -e lint`, `nox -e typecheck`, `nox -e unit_tests`, `nox -e coverage_report`) ## Definition of Done - [ ] TDD issue-capture scenario exists and initially fails (demonstrating the bug) - [ ] Fix is applied: exception is bound and logged in the debug message - [ ] TDD scenario now passes with the fix in place - [ ] No regressions in existing `MigrationRunner` test scenarios - [ ] All nox stages pass - [ ] Coverage >= 97%
freemo added this to the v3.3.0 milestone 2026-04-02 08:20:00 +00:00
Author
Owner

Dependency note: This issue is a child of Epic #362 (Security & Safety Hardening). It does not block any current open issue — it is an independent, low-priority improvement within the same error-handling workstream as #1273.

Per CONTRIBUTING.md dependency conventions: this issue (child) blocks #362 (parent Epic) until resolved.

**Dependency note**: This issue is a child of Epic #362 (Security & Safety Hardening). It does **not** block any current open issue — it is an independent, low-priority improvement within the same error-handling workstream as #1273. Per CONTRIBUTING.md dependency conventions: this issue (child) **blocks** #362 (parent Epic) until resolved.
freemo self-assigned this 2026-04-02 18:45:26 +00:00
freemo removed this from the v3.3.0 milestone 2026-04-07 02:32:16 +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.

Dependencies

No dependencies set.

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