BUG-HUNT: [spec-alignment] ErrorInfo.__init__ missing required argument validation #6929

Open
opened 2026-04-10 05:49:56 +00:00 by HAL9000 · 2 comments
Owner

Bug Report: [Spec-Alignment] — ErrorInfo.init missing required argument validation

Severity Assessment

  • Impact: Invalid ErrorInfo objects can be created with wrong types, causing TypeErrors or AttributeErrors later when the code assumes correct types
  • Likelihood: Medium - occurs when ErrorInfo is instantiated with invalid arguments
  • Priority: High

Location

  • File: src/cleveragents/core/error_handling.py
  • Function/Class: ErrorInfo.__init__()
  • Lines: 213-225

Description

The ErrorInfo constructor violates the project specification requirement that "All public and protected class methods must validate arguments as the first guard". It accepts parameters without any type or value validation, assuming all inputs are correct.

Evidence

def __init__(
    self,
    *,
    code: ErrorCode,
    message: str,
    exception_type: str,
    details: dict[str, Any] | None = None,
) -> None:
    self.code = code  # No validation!
    self.category = ErrorCategory.CLIENT if code < 500 else ErrorCategory.SERVER  # Assumes code is numeric!
    self.message = message  # No validation!
    self.exception_type = exception_type  # No validation!
    self.details = details or {}

Expected Behavior

Per the specification, the method should validate:

  • code is an instance of ErrorCode enum
  • message is a non-empty string
  • exception_type is a non-empty string
  • details is a dict if provided

Actual Behavior

No validation occurs. Passing invalid types like code="500" (string) or message=None would create a broken ErrorInfo object that fails later with confusing errors.

Suggested Fix

Add validation at the start of __init__:

def __init__(self, *, code: ErrorCode, message: str, exception_type: str, details: dict[str, Any] | None = None) -> None:
    # Validate arguments per spec requirement
    if not isinstance(code, ErrorCode):
        raise TypeError(f"code must be ErrorCode, got {type(code).__name__}")
    if not isinstance(message, str) or not message:
        raise ValueError("message must be non-empty string")
    if not isinstance(exception_type, str) or not exception_type:
        raise ValueError("exception_type must be non-empty string")
    if details is not None and not isinstance(details, dict):
        raise TypeError(f"details must be dict or None, got {type(details).__name__}")

    self.code = code
    self.category = ErrorCategory.CLIENT if code < 500 else ErrorCategory.SERVER
    self.message = message
    self.exception_type = exception_type
    self.details = details or {}

Category

spec-alignment

TDD Note

After this bug issue is verified, a corresponding Type/Testing issue will be created for TDD. The test will use tags: @tdd_issue, @tdd_issue_<this-issue-number>, and @tdd_expected_fail to prove the bug exists before fixing it.


Metadata

  • Branch: bugfix/m35-errorinfo-init-argument-validation
  • Commit Message: fix(core): add argument validation to ErrorInfo.__init__ per spec requirement
  • Milestone: Backlog
  • Parent Epic: (orphan — needs manual linking; see comment below)

Subtasks

  • Reproduce the missing-validation bug with a failing TDD test (@tdd_expected_fail)
  • Add isinstance / non-empty checks for code, message, exception_type, and details at the top of ErrorInfo.__init__()
  • Raise TypeError for wrong-type arguments and ValueError for empty strings
  • Verify no existing callers pass invalid arguments (audit call sites)
  • Update docstring for ErrorInfo.__init__() to document the validation contract
  • Run full nox suite; confirm coverage ≥ 97%

Definition of Done

  • ErrorInfo.__init__() validates all arguments as the first guard, per the specification requirement
  • TypeError is raised when code is not an ErrorCode instance or details is not a dict
  • ValueError is raised when message or exception_type is empty or not a string
  • BDD unit test (tagged @tdd_issue, @tdd_issue_<issue-number>) transitions from @tdd_expected_fail to passing after the fix
  • Integration tests pass with no regressions in error handling paths
  • All nox stages pass
  • Coverage >= 97%

Backlog note: This issue was discovered during autonomous operation
on milestone v3.5.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: Acting on behalf of: Bug Hunter | Agent: new-issue-creator

## Bug Report: [Spec-Alignment] — ErrorInfo.__init__ missing required argument validation ### Severity Assessment - **Impact**: Invalid ErrorInfo objects can be created with wrong types, causing TypeErrors or AttributeErrors later when the code assumes correct types - **Likelihood**: Medium - occurs when ErrorInfo is instantiated with invalid arguments - **Priority**: High ### Location - **File**: `src/cleveragents/core/error_handling.py` - **Function/Class**: `ErrorInfo.__init__()` - **Lines**: 213-225 ### Description The `ErrorInfo` constructor violates the project specification requirement that "All public and protected class methods must validate arguments as the first guard". It accepts parameters without any type or value validation, assuming all inputs are correct. ### Evidence ```python def __init__( self, *, code: ErrorCode, message: str, exception_type: str, details: dict[str, Any] | None = None, ) -> None: self.code = code # No validation! self.category = ErrorCategory.CLIENT if code < 500 else ErrorCategory.SERVER # Assumes code is numeric! self.message = message # No validation! self.exception_type = exception_type # No validation! self.details = details or {} ``` ### Expected Behavior Per the specification, the method should validate: - `code` is an instance of `ErrorCode` enum - `message` is a non-empty string - `exception_type` is a non-empty string - `details` is a dict if provided ### Actual Behavior No validation occurs. Passing invalid types like `code="500"` (string) or `message=None` would create a broken `ErrorInfo` object that fails later with confusing errors. ### Suggested Fix Add validation at the start of `__init__`: ```python def __init__(self, *, code: ErrorCode, message: str, exception_type: str, details: dict[str, Any] | None = None) -> None: # Validate arguments per spec requirement if not isinstance(code, ErrorCode): raise TypeError(f"code must be ErrorCode, got {type(code).__name__}") if not isinstance(message, str) or not message: raise ValueError("message must be non-empty string") if not isinstance(exception_type, str) or not exception_type: raise ValueError("exception_type must be non-empty string") if details is not None and not isinstance(details, dict): raise TypeError(f"details must be dict or None, got {type(details).__name__}") self.code = code self.category = ErrorCategory.CLIENT if code < 500 else ErrorCategory.SERVER self.message = message self.exception_type = exception_type self.details = details or {} ``` ### Category spec-alignment ### TDD Note After this bug issue is verified, a corresponding `Type/Testing` issue will be created for TDD. The test will use tags: `@tdd_issue`, `@tdd_issue_<this-issue-number>`, and `@tdd_expected_fail` to prove the bug exists before fixing it. --- ## Metadata - **Branch**: `bugfix/m35-errorinfo-init-argument-validation` - **Commit Message**: `fix(core): add argument validation to ErrorInfo.__init__ per spec requirement` - **Milestone**: Backlog - **Parent Epic**: *(orphan — needs manual linking; see comment below)* ## Subtasks - [ ] Reproduce the missing-validation bug with a failing TDD test (`@tdd_expected_fail`) - [ ] Add `isinstance` / non-empty checks for `code`, `message`, `exception_type`, and `details` at the top of `ErrorInfo.__init__()` - [ ] Raise `TypeError` for wrong-type arguments and `ValueError` for empty strings - [ ] Verify no existing callers pass invalid arguments (audit call sites) - [ ] Update docstring for `ErrorInfo.__init__()` to document the validation contract - [ ] Run full nox suite; confirm coverage ≥ 97% ## Definition of Done - [ ] `ErrorInfo.__init__()` validates all arguments as the first guard, per the specification requirement - [ ] `TypeError` is raised when `code` is not an `ErrorCode` instance or `details` is not a `dict` - [ ] `ValueError` is raised when `message` or `exception_type` is empty or not a string - [ ] BDD unit test (tagged `@tdd_issue`, `@tdd_issue_<issue-number>`) transitions from `@tdd_expected_fail` to passing after the fix - [ ] Integration tests pass with no regressions in error handling paths - [ ] All nox stages pass - [ ] Coverage >= 97% > **Backlog note:** This issue was discovered during autonomous operation > on milestone v3.5.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: Acting on behalf of: Bug Hunter | Agent: new-issue-creator
Author
Owner

⚠️ Orphan Issue — Needs Manual Parent Epic Linking

This issue was created during autonomous bug-hunting and does not yet have a parent Epic linked via Forgejo's dependency system.

Required action: A maintainer should identify the appropriate parent Epic for this spec-alignment / error-handling bug and link it using Forgejo's dependency system:

  • Open this issue and add the parent Epic under "blocks", OR
  • Open the parent Epic and add this issue under "depends on"

This issue is related to src/cleveragents/core/error_handling.py and the ErrorInfo class. Candidate parent Epics may include any Epic covering:

  • Core error handling improvements
  • Spec-alignment work for the core module
  • Argument validation enforcement across the codebase

Per CONTRIBUTING.md: "Orphan issues are not permitted — every atomic change serves a larger capability."


Automated by CleverAgents Bot
Supervisor: Acting on behalf of: Bug Hunter | Agent: new-issue-creator

⚠️ **Orphan Issue — Needs Manual Parent Epic Linking** This issue was created during autonomous bug-hunting and does not yet have a parent Epic linked via Forgejo's dependency system. **Required action:** A maintainer should identify the appropriate parent Epic for this spec-alignment / error-handling bug and link it using Forgejo's dependency system: - Open this issue and add the parent Epic under **"blocks"**, OR - Open the parent Epic and add this issue under **"depends on"** This issue is related to `src/cleveragents/core/error_handling.py` and the `ErrorInfo` class. Candidate parent Epics may include any Epic covering: - Core error handling improvements - Spec-alignment work for the `core` module - Argument validation enforcement across the codebase Per CONTRIBUTING.md: *"Orphan issues are not permitted — every atomic change serves a larger capability."* --- **Automated by CleverAgents Bot** Supervisor: Acting on behalf of: Bug Hunter | Agent: new-issue-creator
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Medium — Spec-alignment issue: ErrorInfo.init missing argument validation. Impact is medium — invalid objects cause downstream TypeErrors, but this is a defensive coding issue rather than a crash bug
  • Milestone: v3.2.0 — Core validation belongs in the earliest milestone as foundational quality
  • Story Points: 2 — S — Add type/value guards to init method
  • MoSCoW: MoSCoW/Should have — Important for spec compliance but not blocking core functionality
  • Parent Epic: Needs linking to error handling epic

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

Issue triaged by project owner: - **State**: Verified - **Priority**: Medium — Spec-alignment issue: ErrorInfo.__init__ missing argument validation. Impact is medium — invalid objects cause downstream TypeErrors, but this is a defensive coding issue rather than a crash bug - **Milestone**: v3.2.0 — Core validation belongs in the earliest milestone as foundational quality - **Story Points**: 2 — S — Add type/value guards to __init__ method - **MoSCoW**: MoSCoW/Should have — Important for spec compliance but not blocking core functionality - **Parent Epic**: Needs linking to error handling epic --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner
HAL9000 self-assigned this 2026-04-10 06:00:03 +00:00
HAL9000 added this to the v3.2.0 milestone 2026-04-10 06:00:03 +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#6929
No description provided.