BUG-HUNT: [error-handling] Broad exception in ProviderRegistry.get_provider #1855

Open
opened 2026-04-02 23:59:25 +00:00 by freemo · 2 comments
Owner

Metadata

  • Branch: fix/error-handling-provider-registry-get-provider
  • Commit Message: fix(providers): raise specific exception in ProviderRegistry.get_provider instead of swallowing and returning None
  • Milestone: v3.2.0
  • Parent Epic: #1669

Bug Report: [error-handling] — Broad exception in ProviderRegistry.get_provider

Severity Assessment

  • Impact: Can swallow multiple exception types and just return None. This could make debugging difficult.
  • Likelihood: High
  • Priority: Medium

Location

  • File: src/cleveragents/providers/registry.py
  • Function/Class: ProviderRegistry.get_provider
  • Lines: ~200

Description

The get_provider method in ProviderRegistry has a broad except (ImportError, AttributeError, TypeError, ValueError) as e:. This is a potential issue as it can swallow multiple exception types and just return None. This could hide the actual cause of the error and make debugging difficult.

Evidence

        try:
            return self._create_provider(info.provider_type, api_key, model_id, **kwargs)
        except (ImportError, AttributeError, TypeError, ValueError) as e:
            logger.error(
                "provider.instantiation_failed",
                provider=provider_name,
                model=model_id,
                error=str(e),
            )
            return None

Expected Behavior

The exception should be logged with more details, and the method should probably re-raise the exception or a custom exception type.

Suggested Fix

Log the full traceback of the exception. Consider re-raising the exception or a custom exception type to provide more context to the caller.

Category

error-handling

Subtasks

  • Write a TDD issue-capture Behave test that proves the bug exists (exception is swallowed and None is returned instead of propagating)
  • Log the full traceback using logger.exception or exc_info=True in the error log call
  • Replace the silent return None with a re-raise of a domain-specific custom exception (e.g. ProviderInstantiationError) that wraps the original exception
  • Define ProviderInstantiationError in the providers module if it does not already exist
  • Update all callers of get_provider to handle the new exception type appropriately
  • 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)
  • ProviderRegistry.get_provider no longer silently returns None on instantiation failure
  • Full exception traceback is logged on failure
  • A domain-specific exception is raised so callers can handle or propagate it explicitly
  • No # type: ignore suppressions introduced
  • All nox stages pass
  • Coverage >= 97%

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

## Metadata - **Branch**: `fix/error-handling-provider-registry-get-provider` - **Commit Message**: `fix(providers): raise specific exception in ProviderRegistry.get_provider instead of swallowing and returning None` - **Milestone**: v3.2.0 - **Parent Epic**: #1669 ## Bug Report: [error-handling] — Broad exception in ProviderRegistry.get_provider ### Severity Assessment - **Impact**: Can swallow multiple exception types and just return `None`. This could make debugging difficult. - **Likelihood**: High - **Priority**: Medium ### Location - **File**: `src/cleveragents/providers/registry.py` - **Function/Class**: `ProviderRegistry.get_provider` - **Lines**: ~200 ### Description The `get_provider` method in `ProviderRegistry` has a broad `except (ImportError, AttributeError, TypeError, ValueError) as e:`. This is a potential issue as it can swallow multiple exception types and just return `None`. This could hide the actual cause of the error and make debugging difficult. ### Evidence ```python try: return self._create_provider(info.provider_type, api_key, model_id, **kwargs) except (ImportError, AttributeError, TypeError, ValueError) as e: logger.error( "provider.instantiation_failed", provider=provider_name, model=model_id, error=str(e), ) return None ``` ### Expected Behavior The exception should be logged with more details, and the method should probably re-raise the exception or a custom exception type. ### Suggested Fix Log the full traceback of the exception. Consider re-raising the exception or a custom exception type to provide more context to the caller. ### Category error-handling ## Subtasks - [ ] Write a TDD issue-capture Behave test that proves the bug exists (exception is swallowed and `None` is returned instead of propagating) - [ ] Log the full traceback using `logger.exception` or `exc_info=True` in the error log call - [ ] Replace the silent `return None` with a re-raise of a domain-specific custom exception (e.g. `ProviderInstantiationError`) that wraps the original exception - [ ] Define `ProviderInstantiationError` in the providers module if it does not already exist - [ ] Update all callers of `get_provider` to handle the new exception type appropriately - [ ] 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) - [ ] `ProviderRegistry.get_provider` no longer silently returns `None` on instantiation failure - [ ] Full exception traceback is logged on failure - [ ] A domain-specific exception is raised so callers can handle or propagate it explicitly - [ ] No `# type: ignore` suppressions introduced - [ ] All nox stages pass - [ ] Coverage >= 97% --- **Automated by CleverAgents Bot** Supervisor: Unknown | Agent: ca-new-issue-creator
freemo added this to the v3.2.0 milestone 2026-04-02 23:59:36 +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
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
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#1855
No description provided.