fix: use missing_ok for temp file cleanup to avoid masking errors - #3820
Open
Quratulain-bilal wants to merge 2 commits into
Open
fix: use missing_ok for temp file cleanup to avoid masking errors#3820Quratulain-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
This PR attempts to prevent temporary-file cleanup from masking write failures.
Changes:
- Replaces existence checks with
Path.unlink(missing_ok=True)in three atomic-write paths. - However, non-
FileNotFoundErrorcleanup failures can still mask original exceptions.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/shared_infra.py |
Updates shared-file cleanup. |
src/specify_cli/integrations/manifest.py |
Updates manifest cleanup. |
src/specify_cli/_utils.py |
Updates settings JSON cleanup. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 3
- Review effort level: Medium
Quratulain-bilal
force-pushed
the
fix/presets-registry-encoding
branch
from
July 29, 2026 13:24
4c32666 to
bbe9657
Compare
Contributor
There was a problem hiding this comment.
Review details
Suppressed comments (3)
src/specify_cli/shared_infra.py:268
- Add a regression test for this new cleanup-failure path. Have the write/replace operation raise a sentinel exception and
Path.unlinkraiseOSError, then assert the sentinel remains the propagated error; otherwise the behavior this PR is intended to guarantee can regress unnoticed.
try:
temp_path.unlink(missing_ok=True)
except OSError:
pass
src/specify_cli/integrations/manifest.py:445
- Add a manifest persistence regression test that forces the save operation to fail and the temporary-file unlink to raise
OSError, and verifies the original save error is preserved. The existing persistence tests cover successful round trips but not the masking scenario introduced here.
try:
temp_path.unlink(missing_ok=True)
except OSError:
pass
src/specify_cli/_utils.py:199
- Please cover this exception branch by making
os.replacefail with a distinguishable original error and cleanup unlink fail withOSError, then assertinghandle_vscode_settingsstill propagates the replace error. Current settings tests only exercise a successful atomic write, so this fix has no regression guard.
if temp_path:
try:
temp_path.unlink(missing_ok=True)
except OSError:
pass
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
- Review effort level: Balanced
Wrap unlink(missing_ok=True) in try/except OSError in finally/except blocks to prevent cleanup failures from masking the original exception.
Quratulain-bilal
force-pushed
the
fix/presets-registry-encoding
branch
from
July 31, 2026 15:20
bbe9657 to
c0d362c
Compare
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.
Replace if temp_path.exists(): temp_path.unlink() with emp_path.unlink(missing_ok=True) in 3 files: integrations/manifest.py, shared_infra.py, _utils.py. The old pattern could raise OSError if unlink() fails, masking the original exception in inally/except blocks.