Skip to content

fix(events): skip an unreadable command template - #3956

Open
marcelsafin wants to merge 2 commits into
github:mainfrom
marcelsafin:fix/event-template-read
Open

fix(events): skip an unreadable command template#3956
marcelsafin wants to merge 2 commits into
github:mainfrom
marcelsafin:fix/event-template-read

Conversation

@marcelsafin

Copy link
Copy Markdown
Contributor

Description

The event command runner reads the resolved command template with a bare read_text(), so a template file that exists but cannot be read or decoded (permission error, non-UTF-8 bytes) crashes event dispatch with a raw OSError/UnicodeDecodeError. Every sibling failure in this path — missing template, unresolvable command — already returns None so the dispatcher falls back cleanly.

Fix: wrap the read and return None on (OSError, UnicodeDecodeError), matching the sibling contract. An unreadable template now behaves exactly like a missing one.

Testing

  • Tested locally with uv run specify --help
  • Ran existing tests with uv sync && uv run pytest (6,310 passed, 176 skipped)
  • New regression test test_unreadable_template_returns_none (fails on main, passes with fix)
  • ruff check src tests clean

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (describe below)

Implemented autonomously by GitHub Copilot CLI (model: Claude Fable 5) under human direction; TDD (failing test first), full suite and lint verified locally. Commit includes Assisted-by/Co-authored-by trailers.

_render_command_template() read the resolved template with a bare
read_text(), so a template file that exists but cannot be read or
decoded (permission error, non-UTF-8 bytes) crashed event dispatch with
a raw OSError/UnicodeDecodeError. Every sibling failure in this path
(missing template, unresolvable command) already returns None so the
dispatcher falls back cleanly.

Wrap the read and return None on OSError/UnicodeDecodeError, matching
the sibling contract.

Assisted-by: GitHub Copilot (model: claude-fable-5, autonomous)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 3, 2026 19:54
@marcelsafin
marcelsafin requested a review from mnriem as a code owner August 3, 2026 19:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Handles unreadable event command templates without crashing dispatch.

Changes:

  • Returns None for template read/decode failures.
  • Adds regression coverage for invalid UTF-8 templates.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/specify_cli/events.py Gracefully handles unreadable templates.
tests/integrations/test_events.py Tests invalid UTF-8 fallback behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/integrations/test_events.py
Review follow-up: add a mocked PermissionError case so both promised
exception paths are protected under privileged CI.

Assisted-by: GitHub Copilot (model: claude-fable-5, autonomous)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 3, 2026 20:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants