Improve synced reader error checking#2024
Open
daviesrob wants to merge 3 commits into
Open
Conversation
As enum bcf_sr_error didn't explicitly set an values, the first entry (open_failed) got the value zero. As a check against zero is suggested in example code (and also used frequently in bcftools) to test for errors, it was not possible to distinguish open_failed from no error. Fix by deprecating open_failed and replacing it by a new non-zero value `bcf_sr_open_failed` to cover the case. A new entry bcf_sr_ok is added to make the OK case explicit. New entries bcf_sr_seek_error, bcf_sr_regions_error, and bcf_sr_samples_error are added for use by later updates. Signed-off-by: Rob Davies <rmd+git@sanger.ac.uk>
Mainly adds tests to ensure that memory allocations worked, along with places where hts_getline() failure may have been missed before. Ensures that errors propagate up to callers, and that bcf_srs_t::errnum is set consistently. Where possible, structures are left in a consistent state when recovering from an allocation failure. For example, fields recording how much memory was allocated are only updated after realloc() succeeds, so it does not appear that more space is available than is really the case. Fixes a couple of places where the synced reader would call exit(1) rather than return an error code to the caller. This does mean callers may have to become better at checking return values. Signed-off-by: Rob Davies <rmd+git@sanger.ac.uk>
Ensure return values are documented. Convert markup to better match doxygen format. Signed-off-by: Rob Davies <rmd+git@sanger.ac.uk>
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.
Mainly adds tests to ensure that memory allocations worked, along with places where
hts_getline()failure may have been missed before. Ensures that errors propagate up to callers, and thatbcf_srs_t::errnumis set consistently.The
bcf_sr_errorenumerated type used forbcf_srs_t::errnumgets two new entriesbcf_sr_seek_errorandbcf_sr_regions_errorfor cases not really covered by the existing values. As the oldopen_failedentry unfortunately had the value zero, which meant it looked like "no error" in the recommended way of checkingbcf_srs_t::errnum, it has been deprecated and replaced bybcf_sr_open_failed. Abcf_sr_okentry is also added with value zero to make the "no errors" case explicit.Where possible, structures are left in a consistent state when recovering from an allocation failure. For example, fields recording how much memory was allocated are only updated after
realloc()succeeds, so it does not appear that more space is available than is really the case.Fixes a couple of places where the synced reader would call
exit(1)rather than return an error code to the caller. This does mean callers may have to become better at checking return values.The synced reader documentation also gets some updates to make it more compatible with doxygen, and to update descriptions of the values returned by some functions.