Skip to content

Add error handling options to CloudPath.rmtree - #604

Merged
pjbull merged 2 commits into
drivendataorg:masterfrom
terminalchai:feat/rmtree-error-handling
Oct 20, 2026
Merged

pjbull merged 2 commits into
drivendataorg:masterfrom
terminalchai:feat/rmtree-error-handling

Conversation

@terminalchai

Copy link
Copy Markdown
Contributor

CloudPath.rmtree() currently rejects ignore_errors and error callbacks, so cleanup code cannot suppress or handle a failed cloud deletion using the standard-library-style API requested in #270.

Add ignore_errors=False, onerror=None, and keyword-only onexc=None to the shared method. Existing calls keep propagating errors. Suppression takes precedence over callbacks; onexc takes precedence over onerror. Callback failures and control-flow exceptions still propagate. No backend SDK calls change.

Callbacks receive the unbound rmtree method, the cloud path and the exception (or the legacy sys.exc_info() tuple), allowing function(path) to retry. This is operation-level handling: it covers the initial file check and the backend removal, and a backend may have removed some objects before failing. The docstring describes these semantics. Cloud SDK errors need not inherit OSError, so the opt-in handler accepts Exception; local-only dir_fd is not exposed.

Closes #270.

Validation on Windows/Python 3.11:

  • Before implementation, the local S3 regression subset had 25 failures for the missing API and 2 passing default-behavior cases.
  • All 270 focused cases pass across the ten mocked/local provider rigs. Coverage includes metadata/removal errors, default exception identity, suppression, callback arguments and precedence, callback failures, successful retries, file-path rejection, successful deletion and propagation of KeyboardInterrupt/SystemExit.
  • Full mocked/local suite: 2,435 passed, 127 skipped.
  • Repository-wide Black and flake8 checks pass; mypy passes on 31 source files; git diff --check passes.
  • Regenerated method-support output; the existing rmtree support row is unchanged. Built MkDocs with the API docstring and changelog; existing link warnings remain.
  • Codex reviewed the production diff, new tests and issue context and found no actionable defects. Review used supplied text; verification commands ran separately.
  • Live cloud backends were not tested locally. Fork workflows and live jobs may require maintainer approval.

Contributor checklist:

  • Read and understood CONTRIBUTING.md
  • Existing issue with maintainer sign-off; Closes Allow ignore_errors flag for CloudPath().rmtree() #270 in summary
  • Based on latest master
  • Failure-before / success-after evidence
  • Shared implementation covers all providers
  • Manual live cloud backend testing
  • Added regression tests
  • Lint passes
  • Tests pass
  • Updated HISTORY.md under UNRELEASED

Prepared with AI assistance; the diff and test results were reviewed before submission.

@terminalchai
terminalchai deployed to reviewed-live-cloud October 15, 2026 22:17 — with GitHub Actions Active
@terminalchai
terminalchai deployed to reviewed-live-cloud October 15, 2026 22:17 — with GitHub Actions Active
@terminalchai
terminalchai deployed to reviewed-live-cloud October 15, 2026 22:17 — with GitHub Actions Active
@terminalchai
terminalchai deployed to reviewed-live-cloud October 15, 2026 22:17 — with GitHub Actions Active
@terminalchai
terminalchai deployed to reviewed-live-cloud October 15, 2026 22:17 — with GitHub Actions Active
@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.6%. Comparing base (fbb3970) to head (2c31a1f).

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #604     +/-   ##
========================================
- Coverage    96.3%   95.6%   -0.7%     
========================================
  Files          30      30             
  Lines        2979    2988      +9     
========================================
- Hits         2869    2857     -12     
- Misses        110     131     +21     
Files with missing lines Coverage Δ
cloudpathlib/cloudpath.py 96.7% <100.0%> (+0.1%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pjbull
pjbull force-pushed the feat/rmtree-error-handling branch from 4b71f4e to 96f8695 Compare October 17, 2026 18:00
@pjbull
pjbull deployed to reviewed-live-cloud October 17, 2026 18:00 — with GitHub Actions Active
@pjbull
pjbull deployed to reviewed-live-cloud October 17, 2026 18:00 — with GitHub Actions Active
@pjbull
pjbull had a problem deploying to reviewed-live-cloud October 17, 2026 18:00 — with GitHub Actions Failure
@pjbull
pjbull deployed to reviewed-live-cloud October 17, 2026 18:00 — with GitHub Actions Active
@pjbull
pjbull deployed to reviewed-live-cloud October 17, 2026 18:00 — with GitHub Actions Active
@pjbull
pjbull deployed to reviewed-live-cloud October 17, 2026 18:05 — with GitHub Actions Active
@pjbull
pjbull force-pushed the feat/rmtree-error-handling branch from 96f8695 to 2c31a1f Compare October 20, 2026 16:30
@pjbull
pjbull deployed to reviewed-live-cloud October 20, 2026 16:30 — with GitHub Actions Active
@pjbull
pjbull deployed to reviewed-live-cloud October 20, 2026 16:30 — with GitHub Actions Active
@pjbull
pjbull deployed to reviewed-live-cloud October 20, 2026 16:30 — with GitHub Actions Active
@pjbull
pjbull deployed to reviewed-live-cloud October 20, 2026 16:30 — with GitHub Actions Active
@pjbull
pjbull deployed to reviewed-live-cloud October 20, 2026 16:30 — with GitHub Actions Active
@pjbull
pjbull merged commit 37fb4fc into drivendataorg:master Oct 20, 2026
34 checks passed

This branch was successfully deployed

1 active deployment
reviewed-live-cloud — 2c31a1f0 Deployed Oct 20, 2026 by pjbull via Live Tests (azure_gen2) #50
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.

Allow ignore_errors flag for CloudPath().rmtree()

2 participants