fix(extensions): start fresh on a non-UTF-8 extension registry - #3954
Open
marcelsafin wants to merge 2 commits into
Open
fix(extensions): start fresh on a non-UTF-8 extension registry#3954marcelsafin wants to merge 2 commits into
marcelsafin wants to merge 2 commits into
Conversation
ExtensionRegistry._load() catches json.JSONDecodeError and FileNotFoundError to start fresh on a corrupted or missing registry, but a registry file with invalid UTF-8 bytes raised UnicodeDecodeError before JSON parsing began, crashing every extension command. Catch UnicodeDecodeError in the same clause: undecodable bytes are the same corruption class as unparseable JSON. OSError stays uncaught on purpose — the data may be intact on disk, and starting fresh would let a later _save() wipe it (same fail-closed reasoning as the workflow catalog cache loader). Assisted-by: GitHub Copilot (model: claude-fable-5, autonomous) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
6 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Handles non-UTF-8 extension registries as corrupted data instead of crashing extension commands.
Changes:
- Catches
UnicodeDecodeErrorduring registry loading. - Adds regression coverage for invalid UTF-8 bytes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/specify_cli/extensions/__init__.py |
Handles undecodable registry content. |
tests/test_extensions.py |
Tests fresh-state fallback for invalid UTF-8. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…eError Review follow-up: _sibling_extension_ids and test_non_utf8_registry_does_not_crash documented the pre-fix _load() contract; reword both as defense-in-depth so the rationale stays true. Assisted-by: GitHub Copilot (model: claude-fable-5, autonomous) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
ExtensionRegistry._load()catchesjson.JSONDecodeErrorandFileNotFoundErrorto start fresh on a corrupted or missing.specify/extensions/.registry, but a registry file containing invalid UTF-8 bytes raisesUnicodeDecodeErrorbefore JSON parsing begins — crashing every extension command with a raw traceback.Repro on main:
Fix: catch
UnicodeDecodeErrorin the same clause — undecodable bytes are the same corruption class as unparseable JSON.OSErrordeliberately stays uncaught: the data may be intact on disk, and starting fresh would let a later_save()wipe it (same fail-closed reasoning as the workflow catalog cache loader).The existing test
test_non_utf8_registry_does_not_crashdocuments that_sibling_extension_idsworks around this gap; this PR fixes the source so the workaround is consistent with_load()itself.Testing
uv run specify --helpuv sync && uv run pytest(6,310 passed, 176 skipped)test_load_starts_fresh_for_non_utf8_registry(fails on main, passes with fix)ruff check src testscleanAI Disclosure
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-bytrailers.