BUG-HUNT: [consistency] ErrorCode.NOT_IMPLEMENTED has no exception mapping #6981

Open
opened 2026-04-10 06:10:49 +00:00 by HAL9000 · 0 comments
Owner

Metadata

  • Branch: fix/consistency-not-implemented-error-code-mapping
  • Commit Message: fix(core): map NotImplementedError to ErrorCode.NOT_IMPLEMENTED in _EXCEPTION_CODE_MAP
  • Milestone: Backlog
  • Parent Epic: #400

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.


Bug Report: [Consistency] — ErrorCode.NOT_IMPLEMENTED has no exception mapping

Severity Assessment

  • Impact: Any exception that should map to HTTP 501 NOT_IMPLEMENTED will incorrectly return 500 INTERNAL, causing incorrect error categorization
  • Likelihood: Medium - occurs whenever NOT_IMPLEMENTED status should be returned
  • Priority: Medium

Location

  • File: src/cleveragents/core/error_handling.py
  • Function/Class: Module-level _EXCEPTION_CODE_MAP
  • Lines: 117, 141-171

Description

The ErrorCode enum defines NOT_IMPLEMENTED (501) but no exception class is mapped to it in _EXCEPTION_CODE_MAP. This means any exception that should return a 501 status will default to 500 INTERNAL, breaking the HTTP-like error code contract.

The project uses HTTP-like status codes as a core design principle (see ErrorCode docstring: "Maps to conventional HTTP status code ranges"). Having a defined code with no reachable mapping path is an internal inconsistency — the 501 slot is dead code from the classification perspective.

Evidence

class ErrorCode(IntEnum):
    # ...
    NOT_IMPLEMENTED = 501  # Defined here
    # ...

_EXCEPTION_CODE_MAP: dict[type[Exception], ErrorCode] = {
    # Domain / client errors
    ValidationError: ErrorCode.VALIDATION_FAILED,
    ResourceNotFoundError: ErrorCode.NOT_FOUND,
    ResourceConflictError: ErrorCode.CONFLICT,
    BusinessRuleViolation: ErrorCode.BAD_REQUEST,
    PlanError: ErrorCode.BAD_REQUEST,
    DomainError: ErrorCode.BAD_REQUEST,
    # Auth
    AuthenticationError: ErrorCode.UNAUTHORIZED,
    AuthorizationError: ErrorCode.FORBIDDEN,
    # Config
    MissingConfigurationError: ErrorCode.CONFIGURATION_ERROR,
    ConfigurationError: ErrorCode.CONFIGURATION_ERROR,
    # Provider
    RateLimitError: ErrorCode.RATE_LIMITED,
    TokenLimitExceededError: ErrorCode.TOKEN_LIMIT,
    ModelNotAvailableError: ErrorCode.MODEL_UNAVAILABLE,
    ProviderError: ErrorCode.PROVIDER_ERROR,
    # Infrastructure
    DatabaseError: ErrorCode.DATABASE_ERROR,
    NetworkError: ErrorCode.NETWORK_ERROR,
    ExternalServiceError: ErrorCode.SERVICE_UNAVAILABLE,
    FileSystemError: ErrorCode.FILESYSTEM_ERROR,
    InfrastructureError: ErrorCode.INTERNAL,
    # Execution
    StreamRoutingError: ErrorCode.STREAM_ERROR,
    ExecutionError: ErrorCode.EXECUTION_ERROR,
    # Catch-all for CleverAgentsError
    CleverAgentsError: ErrorCode.INTERNAL,
    # NOTE: No entry maps to ErrorCode.NOT_IMPLEMENTED (501)!
}

Expected Behavior

There should be a NotImplementedError or a project-specific exception class that maps to ErrorCode.NOT_IMPLEMENTED (501), providing consistent HTTP-like status codes. Every defined ErrorCode value should be reachable via the classification pipeline.

Actual Behavior

No exception maps to 501, so any "not implemented" scenario incorrectly returns 500 INTERNAL. ErrorCode.NOT_IMPLEMENTED is unreachable through classify_error().

Suggested Fix

Either:

  1. Map Python's built-in NotImplementedError to 501:
_EXCEPTION_CODE_MAP: dict[type[Exception], ErrorCode] = {
    # ... existing mappings ...
    NotImplementedError: ErrorCode.NOT_IMPLEMENTED,  # Add this
    # ...
}
  1. Or create a project-specific NotImplementedFeatureError exception class that inherits from CleverAgentsError and map it to 501.

Option 1 is simpler and immediately consistent. Option 2 is more aligned with the project's custom exception hierarchy.

Category

consistency

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.


Subtasks

  • Confirm ErrorCode.NOT_IMPLEMENTED (501) has no entry in _EXCEPTION_CODE_MAP in src/cleveragents/core/error_handling.py
  • Decide approach: map built-in NotImplementedError vs. create a new NotImplementedFeatureError class
  • Implement the chosen fix (add mapping entry, and/or add new exception class to the exception hierarchy)
  • Write BDD scenario: an exception that should produce 501 is correctly classified as ErrorCode.NOT_IMPLEMENTED
  • Verify no other ErrorCode values are similarly unreachable (audit all enum members vs. map values)
  • Run full nox suite; confirm coverage ≥ 97%
  • Update docstring/comments if a new exception class is introduced

Definition of Done

  • At least one exception class maps to ErrorCode.NOT_IMPLEMENTED (501) in _EXCEPTION_CODE_MAP
  • classify_error() correctly returns ErrorCode.NOT_IMPLEMENTED for the mapped exception type
  • BDD scenario added at unit level covering the 501 classification path
  • All nox stages pass
  • Coverage ≥ 97%

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

## Metadata - **Branch**: `fix/consistency-not-implemented-error-code-mapping` - **Commit Message**: `fix(core): map NotImplementedError to ErrorCode.NOT_IMPLEMENTED in _EXCEPTION_CODE_MAP` - **Milestone**: Backlog - **Parent Epic**: #400 > **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. --- ## Bug Report: [Consistency] — ErrorCode.NOT_IMPLEMENTED has no exception mapping ### Severity Assessment - **Impact**: Any exception that should map to HTTP 501 NOT_IMPLEMENTED will incorrectly return 500 INTERNAL, causing incorrect error categorization - **Likelihood**: Medium - occurs whenever NOT_IMPLEMENTED status should be returned - **Priority**: Medium ### Location - **File**: `src/cleveragents/core/error_handling.py` - **Function/Class**: Module-level `_EXCEPTION_CODE_MAP` - **Lines**: 117, 141-171 ### Description The `ErrorCode` enum defines `NOT_IMPLEMENTED` (501) but no exception class is mapped to it in `_EXCEPTION_CODE_MAP`. This means any exception that should return a 501 status will default to 500 INTERNAL, breaking the HTTP-like error code contract. The project uses HTTP-like status codes as a core design principle (see `ErrorCode` docstring: *"Maps to conventional HTTP status code ranges"*). Having a defined code with no reachable mapping path is an internal inconsistency — the 501 slot is dead code from the classification perspective. ### Evidence ```python class ErrorCode(IntEnum): # ... NOT_IMPLEMENTED = 501 # Defined here # ... _EXCEPTION_CODE_MAP: dict[type[Exception], ErrorCode] = { # Domain / client errors ValidationError: ErrorCode.VALIDATION_FAILED, ResourceNotFoundError: ErrorCode.NOT_FOUND, ResourceConflictError: ErrorCode.CONFLICT, BusinessRuleViolation: ErrorCode.BAD_REQUEST, PlanError: ErrorCode.BAD_REQUEST, DomainError: ErrorCode.BAD_REQUEST, # Auth AuthenticationError: ErrorCode.UNAUTHORIZED, AuthorizationError: ErrorCode.FORBIDDEN, # Config MissingConfigurationError: ErrorCode.CONFIGURATION_ERROR, ConfigurationError: ErrorCode.CONFIGURATION_ERROR, # Provider RateLimitError: ErrorCode.RATE_LIMITED, TokenLimitExceededError: ErrorCode.TOKEN_LIMIT, ModelNotAvailableError: ErrorCode.MODEL_UNAVAILABLE, ProviderError: ErrorCode.PROVIDER_ERROR, # Infrastructure DatabaseError: ErrorCode.DATABASE_ERROR, NetworkError: ErrorCode.NETWORK_ERROR, ExternalServiceError: ErrorCode.SERVICE_UNAVAILABLE, FileSystemError: ErrorCode.FILESYSTEM_ERROR, InfrastructureError: ErrorCode.INTERNAL, # Execution StreamRoutingError: ErrorCode.STREAM_ERROR, ExecutionError: ErrorCode.EXECUTION_ERROR, # Catch-all for CleverAgentsError CleverAgentsError: ErrorCode.INTERNAL, # NOTE: No entry maps to ErrorCode.NOT_IMPLEMENTED (501)! } ``` ### Expected Behavior There should be a `NotImplementedError` or a project-specific exception class that maps to `ErrorCode.NOT_IMPLEMENTED` (501), providing consistent HTTP-like status codes. Every defined `ErrorCode` value should be reachable via the classification pipeline. ### Actual Behavior No exception maps to 501, so any "not implemented" scenario incorrectly returns 500 INTERNAL. `ErrorCode.NOT_IMPLEMENTED` is unreachable through `classify_error()`. ### Suggested Fix Either: 1. Map Python's built-in `NotImplementedError` to 501: ```python _EXCEPTION_CODE_MAP: dict[type[Exception], ErrorCode] = { # ... existing mappings ... NotImplementedError: ErrorCode.NOT_IMPLEMENTED, # Add this # ... } ``` 2. Or create a project-specific `NotImplementedFeatureError` exception class that inherits from `CleverAgentsError` and map it to 501. Option 1 is simpler and immediately consistent. Option 2 is more aligned with the project's custom exception hierarchy. ### Category consistency ### 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. --- ## Subtasks - [ ] Confirm `ErrorCode.NOT_IMPLEMENTED` (501) has no entry in `_EXCEPTION_CODE_MAP` in `src/cleveragents/core/error_handling.py` - [ ] Decide approach: map built-in `NotImplementedError` vs. create a new `NotImplementedFeatureError` class - [ ] Implement the chosen fix (add mapping entry, and/or add new exception class to the exception hierarchy) - [ ] Write BDD scenario: an exception that should produce 501 is correctly classified as `ErrorCode.NOT_IMPLEMENTED` - [ ] Verify no other `ErrorCode` values are similarly unreachable (audit all enum members vs. map values) - [ ] Run full nox suite; confirm coverage ≥ 97% - [ ] Update docstring/comments if a new exception class is introduced ## Definition of Done - [ ] At least one exception class maps to `ErrorCode.NOT_IMPLEMENTED` (501) in `_EXCEPTION_CODE_MAP` - [ ] `classify_error()` correctly returns `ErrorCode.NOT_IMPLEMENTED` for the mapped exception type - [ ] BDD scenario added at unit level covering the 501 classification path - [ ] All nox stages pass - [ ] Coverage ≥ 97% --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: new-issue-creator
HAL9000 self-assigned this 2026-04-10 06:21:49 +00:00
HAL9000 added this to the v3.2.0 milestone 2026-04-10 06:21:49 +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.

Blocks
#400 Epic: Post-MVP Security
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#6981
No description provided.