Skip to content

Commit b1156cc

Browse files
fix: use missing_ok for temp file cleanup to avoid masking errors
1 parent 186ca25 commit b1156cc

3 files changed

Lines changed: 4 additions & 6 deletions

File tree

‎src/specify_cli/_utils.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ def atomic_write_json(target_file: Path, payload: dict[str, Any]) -> None:
192192

193193
os.replace(temp_path, target_file)
194194
except Exception:
195-
if temp_path and temp_path.exists():
196-
temp_path.unlink()
195+
if temp_path:
196+
temp_path.unlink(missing_ok=True)
197197
raise
198198

199199
try:

‎src/specify_cli/integrations/manifest.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,7 @@ def save(self) -> Path:
439439
_ensure_safe_manifest_destination(self.project_root, path)
440440
os.replace(temp_path, path)
441441
finally:
442-
if temp_path.exists():
443-
temp_path.unlink()
442+
temp_path.unlink(missing_ok=True)
444443
return path
445444

446445
@classmethod

‎src/specify_cli/shared_infra.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,7 @@ def _write_shared_bytes(
262262
_ensure_safe_shared_destination(project_path, dest)
263263
os.replace(temp_path, dest)
264264
finally:
265-
if temp_path.exists():
266-
temp_path.unlink()
265+
temp_path.unlink(missing_ok=True)
267266

268267

269268
_BASH_FORMAT_COMMAND_RE = re.compile(

0 commit comments

Comments
 (0)