Skip to content

Report cwd failures to the parent process - #86

Open
Zhuyuyangyy wants to merge 2 commits into
pexpect:masterfrom
Zhuyuyangyy:fix/cwd-error-propagation
Open

Zhuyuyangyy wants to merge 2 commits into
pexpect:masterfrom
Zhuyuyangyy:fix/cwd-error-propagation

Conversation

@Zhuyuyangyy

Copy link
Copy Markdown

Related to pexpect/pexpect#757.

os.chdir(cwd) runs in the forked child outside the existing OSError reporting boundary. If the directory is missing or is a regular file, the child-side exception can escape into the caller's Python code while the parent receives a PtyProcess as though startup succeeded. In interactive use, this can leave the parent waiting for the child to exec.

Include the directory change in the existing error-pipe boundary, retaining the current order of chdir, preexec_fn, and exec. Reuse the existing OSError/errno protocol rather than prechecking the path in the parent.

The new tests run invalid-cwd calls in isolated interpreters so that a broken forked child cannot resume the test suite. They cover a missing directory, a regular file used as cwd, and a valid directory with preexec_fn running after the directory change and without changing the parent's cwd.

Validation on Linux / Python 3.12.3:

  • Unchanged base 12d3221806c0a7cf114b894101814b1f9e338ed4: python3 -m unittest tests.test_cwd -v — 2 expected regression failures, 1 valid-cwd control passed.
  • Patched: python3 -m unittest discover -v — all 18 tests passed.
  • python3 -m compileall -q ptyprocess tests/test_cwd.py — passed.
  • git diff --check — passed.

Other Python versions and operating systems were not tested. This is a dependency-level fix; it does not itself publish a new ptyprocess release or change pexpect's dependency requirements.

AI-assisted investigation, implementation, tests, review, and PR description. No independent human review is claimed.

Include chdir in the existing OSError reporting boundary while preserving preexec_fn ordering.
Use isolated interpreters for invalid cwd regressions, and retain a valid cwd/preexec control.
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