BUG-HUNT: [error-handling] Generic exception handling in schema validation #1323

Open
opened 2026-04-02 16:49:27 +00:00 by freemo · 0 comments
Owner

Bug Report: [error-handling] — Generic exception handling in schema validation

Severity Assessment

  • Impact: Catching a generic Exception can hide unexpected errors and make debugging difficult.
  • Likelihood: Low. A ValidationError is the most likely exception.
  • Priority: Low

Location

  • File: src/cleveragents/actor/loader.py
  • Function/Class: discover
  • Lines: 123-145

Description

The discover method in loader.py catches a generic Exception when validating the actor schema. This is too broad and can hide unexpected errors. It should catch a more specific exception, such as ValidationError from pydantic.

Evidence

            try:
                config = ActorConfigSchema.model_validate(raw)
            except Exception as exc:
                from pydantic import ValidationError as PydanticValidationError

                if isinstance(exc, PydanticValidationError):
                    field_errors = []
                    for err in exc.errors():
                        field_path = ".".join(str(loc) for loc in err["loc"])
                        field_errors.append(f"  {field_path}: {err['msg']}")
                    detail = "\n".join(field_errors)
                    hint = (
                        "  Hint: see docs/reference/actor_config.md "
                        "for the correct schema format."
                    )
                    errors.append(
                        f"Schema validation failed for {path.name}:\n{detail}\n{hint}"
                    )
                else:
                    errors.append(
                        f"Schema validation failed for {path.name}: {exc}"
                    )
                continue

Expected Behavior

The function should catch a more specific exception, such as pydantic.ValidationError.

Actual Behavior

The function catches a generic Exception and then checks if it is a ValidationError.

Suggested Fix

Change except Exception as exc: to except ValidationError as exc:.

Category

error-handling

## Bug Report: [error-handling] — Generic exception handling in schema validation ### Severity Assessment - **Impact**: Catching a generic `Exception` can hide unexpected errors and make debugging difficult. - **Likelihood**: Low. A `ValidationError` is the most likely exception. - **Priority**: Low ### Location - **File**: `src/cleveragents/actor/loader.py` - **Function/Class**: `discover` - **Lines**: 123-145 ### Description The `discover` method in `loader.py` catches a generic `Exception` when validating the actor schema. This is too broad and can hide unexpected errors. It should catch a more specific exception, such as `ValidationError` from pydantic. ### Evidence ```python try: config = ActorConfigSchema.model_validate(raw) except Exception as exc: from pydantic import ValidationError as PydanticValidationError if isinstance(exc, PydanticValidationError): field_errors = [] for err in exc.errors(): field_path = ".".join(str(loc) for loc in err["loc"]) field_errors.append(f" {field_path}: {err['msg']}") detail = "\n".join(field_errors) hint = ( " Hint: see docs/reference/actor_config.md " "for the correct schema format." ) errors.append( f"Schema validation failed for {path.name}:\n{detail}\n{hint}" ) else: errors.append( f"Schema validation failed for {path.name}: {exc}" ) continue ``` ### Expected Behavior The function should catch a more specific exception, such as `pydantic.ValidationError`. ### Actual Behavior The function catches a generic `Exception` and then checks if it is a `ValidationError`. ### Suggested Fix Change `except Exception as exc:` to `except ValidationError as exc:`. ### Category error-handling
freemo self-assigned this 2026-04-02 18:45:23 +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#1323
No description provided.