fix(presets): start fresh on a non-UTF-8 preset registry - #3955
Open
marcelsafin wants to merge 1 commit into
Open
fix(presets): start fresh on a non-UTF-8 preset registry#3955marcelsafin wants to merge 1 commit into
marcelsafin wants to merge 1 commit into
Conversation
PresetRegistry._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 preset 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>
Contributor
There was a problem hiding this comment.
Pull request overview
Handles non-UTF-8 preset registries as corrupted data instead of crashing.
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 1 comment.
| File | Description |
|---|---|
src/specify_cli/presets/__init__.py |
Recovers from undecodable registry files. |
tests/test_presets.py |
Tests non-UTF-8 registry recovery. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
PresetRegistry._load()catchesjson.JSONDecodeErrorandFileNotFoundErrorto start fresh on a corrupted or missing.specify/presets/.registry, but a registry file containing invalid UTF-8 bytes raisesUnicodeDecodeErrorbefore JSON parsing begins — crashing every preset 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).Exact twin of the extension-registry gap (#3954), kept as a separate PR per bug for isolated review/revert.
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.