Skip to content

Handle scandir iteration errors in tree walkers - #174

Draft
AlexXuz wants to merge 1 commit into
cpburnz:masterfrom
AlexXuz:fix-scandir-iteration-errors
Draft

AlexXuz wants to merge 1 commit into
cpburnz:masterfrom
AlexXuz:fix-scandir-iteration-errors

Conversation

@AlexXuz

@AlexXuz AlexXuz commented Oct 28, 2026

Copy link
Copy Markdown

Summary

iter_tree_entries() and iter_tree_files() handle errors opening a directory and inspecting its entries, but an OSError raised while advancing an already-open os.scandir() iterator escapes without reaching on_error.

Handle scan-advancement errors using the existing contract: ignore the error when no handler is supplied, otherwise call the handler once with the original exception. Preserve entries already yielded and continue walking healthy sibling directories. Exceptions raised by the handler still propagate, and the scan context is closed.

The shared helper guards only next(entries), not entry processing or callback execution. The change history is updated in both its source and generated file.

Regression coverage

This is a synthetic directory-read-error reproduction, not a claim of a production incident. The tests inject an iterator that yields an entry and then raises OSError(EIO), plus a failing child scan alongside a healthy sibling.

Two new test methods cover both tree walkers, ignore/record/raise modes, original exception identity, once-only callbacks, context cleanup, partial results, and sibling traversal. Their eight subcases produce six errors and two failures against the unchanged base; all pass with the patch.

Validation

  • python -m unittest discover -t . -s tests/: OK on Python 3.12.14 and 3.13.5, each reporting 292 tests and 786 skipped cases/subcases. Optional RE2/Hyperscan backends were not installed.
  • Independent review and a separate full-suite run passed.
  • Python 3.9 grammar parsing passed; this is not a Python 3.9 runtime test.
  • git diff --check: passed.

Windows, other Python runtimes, optional native backends, type checking, and documentation builds were not run.

Prepared and reviewed with AI assistance; no human code review is claimed.

This branch has not been deployed

No deployments
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.

1 participant