Skip to content

Widen suppress(FileNotFoundError) to suppress(OSError) in cleanup paths - #2650

Closed
TrueFurina wants to merge 1 commit into
TencentCloud:mainfrom
TrueFurina:fix/widen-suppress-oserror
Closed

TrueFurina wants to merge 1 commit into
TencentCloud:mainfrom
TrueFurina:fix/widen-suppress-oserror

Conversation

@TrueFurina

Copy link
Copy Markdown

Widen suppress(FileNotFoundError) to suppress(OSError) in cleanup paths

Two cleanup paths used contextlib.suppress(FileNotFoundError) around
os.remove() / os.unlink(), which leaves Windows PermissionError (file
held open by another process) unhandled. On Windows these finally-block
cleanups would raise and shadow the primary exception.

Both sites are best-effort cleanup in finally/except blocks — OSError
is the correct catch-all for any filesystem-level failure during
teardown:

  • tccli-oauth-helper.py clear_state(): state file cleanup
  • clinical_profile.py _atomic_write(): temporary file cleanup after os.replace

Two cleanup paths used contextlib.suppress(FileNotFoundError) around
os.remove() / os.unlink(), which leaves Windows PermissionError (file
held open by another process) unhandled. On Windows these finally-block
cleanups would raise and shadow the primary exception.

Both sites are best-effort cleanup in finally/except blocks — OSError
is the correct catch-all for any filesystem-level failure during
teardown:

- tccli-oauth-helper.py clear_state(): state file cleanup
- clinical_profile.py _atomic_write(): temporary file cleanup after os.replace
@jubaoliang jubaoliang closed this Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants