-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle StopIteration
in iterable_subprocess
#562
Handle StopIteration
in iterable_subprocess
#562
Conversation
This commit modifies `iterable_subprocess` so that it prioritizes `IterableSubprocessError` exceptions over `StopIteration` exceptions, if a `StopIteration` exception is raised in the body of an `iterable_subprocess`-context and if the sub process exits with a non-zero return code. `StopIteration` in conjunction with a non-zero return code indicates an unexpected short read due to an early "error"-exit of the sub process. This commit is a result of this discussion: datalad#546 (comment)
This commit adds tests that verify the intendend behavior of `iterable_subprocess` if a `StopIteration`-exception is raised in the body of an `iterable_subprocess`-context.
This commit ensures that the `LANG` environment variable is set to `C` in a tests that interprets the output of `ls`.
This commit describes the handling of exceptions in the docstring of `iter_subproc`. It highlights the difference between `StopIteration` and other exceptions, in connection with a non-zero subprocess return code.
I am wondering whether it would be better to change The instances of this class could then store the return code of the subprocess and it would still be available to us, independent from the exceptions that were raised. Converting this to Draft for now |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #562 +/- ##
==========================================
+ Coverage 92.87% 92.89% +0.01%
==========================================
Files 143 143
Lines 10365 10393 +28
Branches 1141 1147 +6
==========================================
+ Hits 9627 9655 +28
Misses 714 714
Partials 24 24 ☔ View full report in Codecov by Sentry. |
Ok, I will create another PR that turns the |
With #565 merged, we can close this one. |
[This has been put into draft-mode in favor of an alternative approach to make return codes available in case of exceptions in PR #565]
This PR implements the result of this discussion in PR #546
It modifies
iterable_subprocess
and thereforeiter_subproc
to prioritizeIterableSubprocessError
-exceptions overStopIteration
-exception. The rationale for that is, thatStopIteration
and a non-zero exit value of a subprocess indicate that there was a short-read due to an error in the subprocess.Because we require access to the return code of the subprocess, prioritizing
IterableSubprocessError
-exceptions overStopIteration
-exceptions alleviates the need to catchStopIteration
in theiter_subproc
-context.