BUG-HUNT: [error-handling] Unhandled exception in from_yaml_file #1682

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

Metadata

  • Branch: fix/error-handling-action-schema-from-yaml-file
  • Commit Message: fix(action): handle IOError and UnicodeDecodeError in ActionConfigSchema.from_yaml_file
  • Milestone: v3.6.0
  • Parent Epic: ⚠️ No parent Epic provided — requires manual linking by a maintainer.

Subtasks

  • Wrap filepath.read_text(encoding="utf-8") in a try...except block in ActionConfigSchema.from_yaml_file (src/cleveragents/action/schema.py, line 411)
  • Catch IOError (covers OSError, FileNotFoundError, PermissionError) and UnicodeDecodeError specifically
  • Re-raise as ValueError with a user-friendly error message that includes the file path and original exception detail
  • Tests (Behave): Add scenario for IOError when file cannot be read (e.g. missing file, permission denied)
  • Tests (Behave): Add scenario for UnicodeDecodeError when file contains non-UTF-8 bytes
  • Tests (Behave): Verify the raised ValueError message contains the file path
  • Run nox -e typecheck — confirm no Pyright errors introduced
  • Run nox -e coverage_report — confirm coverage remains >= 97%
  • Run nox (all default sessions) — confirm all stages pass

Definition of Done

  • All subtasks above are completed and checked off
  • ActionConfigSchema.from_yaml_file catches IOError and UnicodeDecodeError and raises ValueError with a user-friendly message
  • No bare except or generic Exception catch introduced — only specific exception types are caught
  • 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 lines providing relevant details about the implementation
  • 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%

Bug Report: [error-handling] — Unhandled exception in from_yaml_file

Severity Assessment

  • Impact: The application could crash if a file with invalid encoding is provided.
  • Likelihood: Low, as most files are expected to be UTF-8 encoded.
  • Priority: Medium

Location

  • File: src/cleveragents/action/schema.py
  • Function/Class: ActionConfigSchema.from_yaml_file
  • Lines: 411

Description

The from_yaml_file method in ActionConfigSchema does not handle potential IOError or UnicodeDecodeError exceptions that can be raised by filepath.read_text(encoding="utf-8"). This can lead to an unhandled exception and a crash of the application if a file with an invalid encoding is provided.

Evidence

        content = filepath.read_text(encoding="utf-8")
        return cls.from_yaml(content)

Expected Behavior

The from_yaml_file method should handle IOError and UnicodeDecodeError exceptions and raise a ValueError with a user-friendly error message.

Suggested Fix

Wrap the filepath.read_text call in a try...except block and handle the exceptions:

try:
    content = filepath.read_text(encoding="utf-8")
except (IOError, UnicodeDecodeError) as exc:
    raise ValueError(
        f"Failed to read action config file '{filepath}': {exc}"
    ) from exc
return cls.from_yaml(content)

Category

error-handling


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

## Metadata - **Branch**: `fix/error-handling-action-schema-from-yaml-file` - **Commit Message**: `fix(action): handle IOError and UnicodeDecodeError in ActionConfigSchema.from_yaml_file` - **Milestone**: v3.6.0 - **Parent Epic**: ⚠️ *No parent Epic provided — requires manual linking by a maintainer.* ## Subtasks - [ ] Wrap `filepath.read_text(encoding="utf-8")` in a `try...except` block in `ActionConfigSchema.from_yaml_file` (`src/cleveragents/action/schema.py`, line 411) - [ ] Catch `IOError` (covers `OSError`, `FileNotFoundError`, `PermissionError`) and `UnicodeDecodeError` specifically - [ ] Re-raise as `ValueError` with a user-friendly error message that includes the file path and original exception detail - [ ] Tests (Behave): Add scenario for `IOError` when file cannot be read (e.g. missing file, permission denied) - [ ] Tests (Behave): Add scenario for `UnicodeDecodeError` when file contains non-UTF-8 bytes - [ ] Tests (Behave): Verify the raised `ValueError` message contains the file path - [ ] Run `nox -e typecheck` — confirm no Pyright errors introduced - [ ] Run `nox -e coverage_report` — confirm coverage remains >= 97% - [ ] Run `nox` (all default sessions) — confirm all stages pass ## Definition of Done - [ ] All subtasks above are completed and checked off - [ ] `ActionConfigSchema.from_yaml_file` catches `IOError` and `UnicodeDecodeError` and raises `ValueError` with a user-friendly message - [ ] No bare `except` or generic `Exception` catch introduced — only specific exception types are caught - [ ] 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 lines providing relevant details about the implementation - [ ] 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% --- ## Bug Report: [error-handling] — Unhandled exception in `from_yaml_file` ### Severity Assessment - **Impact**: The application could crash if a file with invalid encoding is provided. - **Likelihood**: Low, as most files are expected to be UTF-8 encoded. - **Priority**: Medium ### Location - **File**: `src/cleveragents/action/schema.py` - **Function/Class**: `ActionConfigSchema.from_yaml_file` - **Lines**: 411 ### Description The `from_yaml_file` method in `ActionConfigSchema` does not handle potential `IOError` or `UnicodeDecodeError` exceptions that can be raised by `filepath.read_text(encoding="utf-8")`. This can lead to an unhandled exception and a crash of the application if a file with an invalid encoding is provided. ### Evidence ```python content = filepath.read_text(encoding="utf-8") return cls.from_yaml(content) ``` ### Expected Behavior The `from_yaml_file` method should handle `IOError` and `UnicodeDecodeError` exceptions and raise a `ValueError` with a user-friendly error message. ### Suggested Fix Wrap the `filepath.read_text` call in a `try...except` block and handle the exceptions: ```python try: content = filepath.read_text(encoding="utf-8") except (IOError, UnicodeDecodeError) as exc: raise ValueError( f"Failed to read action config file '{filepath}': {exc}" ) from exc return cls.from_yaml(content) ``` ### Category error-handling --- **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:17 +00:00
Author
Owner

⚠️ Orphan Issue — Manual Linking Required

This issue was created without a parent Epic. Per CONTRIBUTING.md, all issues must be linked to a parent Epic using Forgejo's dependency system (child blocks parent).

A maintainer should identify the appropriate parent Epic for this bug (e.g., a broader BUG-HUNT: [error-handling] Epic covering the action/ module) and create the dependency link:

# This issue (#1682) should BLOCK the parent Epic
POST /api/v1/repos/cleveragents/cleveragents-core/issues/1682/blocks
{"dependency_id": <PARENT_EPIC_NUMBER>}

Candidate parent Epics to consider:

  • #1409BUG-HUNT: [error-handling] Review error handling in src/cleveragents/services (covers services module; may need a parallel Epic for the action/ module)

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

⚠️ **Orphan Issue — Manual Linking Required** This issue was created without a parent Epic. Per `CONTRIBUTING.md`, all issues must be linked to a parent Epic using Forgejo's dependency system (child **blocks** parent). A maintainer should identify the appropriate parent Epic for this bug (e.g., a broader `BUG-HUNT: [error-handling]` Epic covering the `action/` module) and create the dependency link: ``` # This issue (#1682) should BLOCK the parent Epic POST /api/v1/repos/cleveragents/cleveragents-core/issues/1682/blocks {"dependency_id": <PARENT_EPIC_NUMBER>} ``` Candidate parent Epics to consider: - **#1409** — `BUG-HUNT: [error-handling] Review error handling in src/cleveragents/services` (covers services module; may need a parallel Epic for the `action/` module) --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: ca-new-issue-creator
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#1682
No description provided.