fix: skip corrupted state.json in list_runs() instead of aborting - #3904
Open
Quratulain-bilal wants to merge 2 commits into
Open
fix: skip corrupted state.json in list_runs() instead of aborting#3904Quratulain-bilal wants to merge 2 commits into
Quratulain-bilal wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates workflow run discovery to skip unreadable or malformed state files instead of aborting.
Changes:
- Catches filesystem, JSON decoding, and Unicode decoding errors.
- Continues listing subsequent valid runs.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/workflows/engine.py |
Adds fault tolerance when loading run state. |
Review details
Tip
Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Balanced
| with open(state_path, encoding="utf-8") as f: | ||
| state_data = json.load(f) | ||
| runs.append(state_data) | ||
| except (OSError, json.JSONDecodeError, UnicodeDecodeError): |
Remove exists() check before open() and catch FileNotFoundError directly. This prevents a race where the file is deleted between check and open, while preserving the descriptive error message.
Catch OSError, JSONDecodeError, and UnicodeDecodeError to skip bad entries gracefully so valid runs are still listed. Add regression tests: - test_list_skips_invalid_utf8_with_valid_sibling - test_list_skips_oserror_with_valid_sibling
Quratulain-bilal
force-pushed
the
fix/list-runs-error-handling
branch
from
August 10, 2026 20:41
5147879 to
827f536
Compare
Contributor
There was a problem hiding this comment.
Review details
Suppressed comments (2)
src/specify_cli/workflows/engine.py:748
- Removing the
state_path.exists()call makes theload()explanation at lines 736–737—and the matching traversal-test explanation—stale because they still say thatexists()probes the path. Update both descriptions to refer to the direct open/read performed here so the security rationale matches the implementation.
try:
with open(state_path, encoding="utf-8") as f:
src/specify_cli/workflows/engine.py:750
- The PR describes adding these exception catches to
list_runs(), but that method's handler at line 1717 is unchanged and already catchesJSONDecodeError,OSError, andUnicodeDecodeError. The only production change instead refactorsRunState.load(), so this branch does not contain the stated fix. Please either apply the intendedlist_runs()change against the correct base, or revise the PR scope and remove or explain this unrelated refactor.
This issue also appears on line 747 of the same file.
try:
with open(state_path, encoding="utf-8") as f:
state_data = json.load(f)
except FileNotFoundError:
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Balanced
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.
Problem
If any single
state.jsonfile is corrupted, truncated, or unreadable, the unhandled exception aborts the entire iteration and all subsequent valid runs are never listed.Fix
Catch
OSError,JSONDecodeError, andUnicodeDecodeErrorto skip bad entries gracefully.Testing