Fix silent truncation in IteratorRowAllRefs on I/O errors#1379
Open
gileshall wants to merge 1 commit intopysam-developers:masterfrom
Open
Fix silent truncation in IteratorRowAllRefs on I/O errors#1379gileshall wants to merge 1 commit intopysam-developers:masterfrom
gileshall wants to merge 1 commit intopysam-developers:masterfrom
Conversation
IteratorRowAllRefs.__next__() only checked `retval > 0` to decide whether a record was available. All non-positive return values, including I/O errors (retval < -1) and truncated files (retval == -2), were silently treated as end-of-reference and the iterator advanced to the next tid. This caused `samfile.fetch()` without a region to silently yield truncated results on read errors with no exception. Add explicit error checks matching the pattern already used by IteratorRowRegion: raise IOError on retval < -1, only treat retval == -1 as normal end-of-reference.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
IteratorRowAllRefs.__next__()(used bysamfile.fetch()without a region) only checkedretval > 0to decide whether a record was available. All non-positive return values — including I/O errors (retval < -1) and truncated files (retval == -2) — were silently treated as end-of-reference, causing the iterator to advance to the nexttid. On a read error mid-file, callers getStopIterationinstead of an exception and have no indication that results are incomplete.Every other iterator in pysam (
IteratorRowRegion,IteratorRowAll,IteratorRowHead,IteratorRowSelection,VariantFile, etc.) already distinguishes EOF from error.IteratorRowAllRefswas the only one missing this check.Add explicit error checks matching the pattern used by
IteratorRowRegion: raiseIOErroronretval < -1, only treatretval == -1as normal end-of-reference.