BUG-HUNT: [error-handling] Unhandled exception in ActionConfigSchema.from_yaml #1680

Open
opened 2026-04-02 23:28:40 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: fix/error-handling-action-schema-from-yaml
  • Commit Message: fix(action): handle YAMLError in ActionConfigSchema.from_yaml to prevent unhandled crash
  • Milestone: v3.6.0
  • Parent Epic: #1613

Description

The from_yaml method in ActionConfigSchema (located at src/cleveragents/action/schema.py, line 369) calls yaml.safe_load(yaml_string) without wrapping it in a try...except block. The yaml.safe_load function can raise a yaml.YAMLError if the provided string is not valid YAML. This unhandled exception will propagate as an uncaught error and crash the application whenever a user or caller provides malformed YAML input.

Per the project specification and CONTRIBUTING.md code standards:

  • Public and protected methods must validate arguments as the first step (fail-fast).
  • Exceptions should only be caught when there is a meaningful recovery action; however, converting a library-specific exception (yaml.YAMLError) into a user-friendly ValueError is a valid and expected pattern for public API methods.

Evidence

# src/cleveragents/action/schema.py, line ~369
raw = yaml.safe_load(yaml_string)

Expected Behavior

The from_yaml method should catch yaml.YAMLError and re-raise it as a ValueError with a clear, user-friendly error message indicating that the provided YAML is invalid.

Suggested Fix

try:
    raw = yaml.safe_load(yaml_string)
except yaml.YAMLError as exc:
    raise ValueError(f"Invalid YAML provided to from_yaml: {exc}") from exc

Subtasks

  • Locate ActionConfigSchema.from_yaml in src/cleveragents/action/schema.py (line ~369)
  • Wrap yaml.safe_load(yaml_string) in a try...except yaml.YAMLError block
  • Re-raise as ValueError with a descriptive message
  • Add Behave scenario: from_yaml raises ValueError when given invalid YAML
  • Add Behave scenario: from_yaml succeeds and returns correct schema for valid YAML
  • Verify coverage >= 97% via nox -e coverage_report
  • Run all nox sessions (nox) and confirm all pass

Definition of Done

  • ActionConfigSchema.from_yaml wraps yaml.safe_load in a try...except yaml.YAMLError block and raises ValueError on parse failure
  • Behave scenarios cover both the error path (invalid YAML → ValueError) and the happy path
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional details and ISSUES CLOSED: #<this issue number>
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done
  • All nox stages pass
  • Coverage >= 97%

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

## Metadata - **Branch**: `fix/error-handling-action-schema-from-yaml` - **Commit Message**: `fix(action): handle YAMLError in ActionConfigSchema.from_yaml to prevent unhandled crash` - **Milestone**: v3.6.0 - **Parent Epic**: #1613 ## Description The `from_yaml` method in `ActionConfigSchema` (located at `src/cleveragents/action/schema.py`, line 369) calls `yaml.safe_load(yaml_string)` without wrapping it in a `try...except` block. The `yaml.safe_load` function can raise a `yaml.YAMLError` if the provided string is not valid YAML. This unhandled exception will propagate as an uncaught error and crash the application whenever a user or caller provides malformed YAML input. Per the project specification and CONTRIBUTING.md code standards: - Public and protected methods must validate arguments as the first step (fail-fast). - Exceptions should only be caught when there is a meaningful recovery action; however, converting a library-specific exception (`yaml.YAMLError`) into a user-friendly `ValueError` is a valid and expected pattern for public API methods. ### Evidence ```python # src/cleveragents/action/schema.py, line ~369 raw = yaml.safe_load(yaml_string) ``` ### Expected Behavior The `from_yaml` method should catch `yaml.YAMLError` and re-raise it as a `ValueError` with a clear, user-friendly error message indicating that the provided YAML is invalid. ### Suggested Fix ```python try: raw = yaml.safe_load(yaml_string) except yaml.YAMLError as exc: raise ValueError(f"Invalid YAML provided to from_yaml: {exc}") from exc ``` ## Subtasks - [ ] Locate `ActionConfigSchema.from_yaml` in `src/cleveragents/action/schema.py` (line ~369) - [ ] Wrap `yaml.safe_load(yaml_string)` in a `try...except yaml.YAMLError` block - [ ] Re-raise as `ValueError` with a descriptive message - [ ] Add Behave scenario: `from_yaml` raises `ValueError` when given invalid YAML - [ ] Add Behave scenario: `from_yaml` succeeds and returns correct schema for valid YAML - [ ] Verify coverage >= 97% via `nox -e coverage_report` - [ ] Run all nox sessions (`nox`) and confirm all pass ## Definition of Done - [ ] `ActionConfigSchema.from_yaml` wraps `yaml.safe_load` in a `try...except yaml.YAMLError` block and raises `ValueError` on parse failure - [ ] Behave scenarios cover both the error path (invalid YAML → `ValueError`) and the happy path - [ ] A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional details and `ISSUES CLOSED: #<this issue number>` - [ ] The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly - [ ] The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done - [ ] All nox stages pass - [ ] Coverage >= 97% --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: ca-new-issue-creator
freemo added this to the v3.6.0 milestone 2026-04-02 23:29:01 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • MoSCoW: MoSCoW/Should Have — bug or spec compliance issue.

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

Issue triaged by project owner: - **State**: Verified - **MoSCoW**: MoSCoW/Should Have — bug or spec compliance issue. --- **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
#1613 Bug Hunter Coordination
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#1680
No description provided.