hts_log_error() extension for better error reporting
@whitwham is already working on this.
Since Feb 15, 2022.
Assessment
This issue has not been assessed yet.
Description
Hi there!
This is more of a general suggestion to improve error reporting, but I'll illustrate it with a concrete example.
I have started using the sam/bam/cram functionality recently, and got an (expected) error "The input is not sorted" on an unsorted bam file during testing. This error is reported in bam_plp_push() here, but not propagated from there to the original caller of the function - the error status gets lost.
My code calls bam_plp_auto(), and checks the result for null to detect whether the current position is usable (I gathered that this is the way this is to be used). That function returns a bam_plp_s* (typedef'ed as bam_plp_t), which however is only declared in the sam.h header, and then defined in sam.c here. Hence, the bam_plp_t field error, which is correctly set by bam_plp_push(), is not accessible from my code to check whether an error occurred.
Furthermore, hts_log() here prints the error directly to stderr, and hence further complicates for me to catch this and report any errors (in my case, via throwing an exception in C++).
It seems hence impossible for me to detect in my code whether a file has simply ended or has an error during iteration.
This all is of course only an example, and seems applicable to many other functions as well. Am I overlooking a simple solution here? What would be a good way of solving this?
One idea that might improve the situation is to offer to set a callback function that gets called in hts_log() with the htsLogLevel and the final error message. Users could then set this callback, and react in their own code to the error message, for example by throwing an exception (or whatever C users do in that situation :-D).
Thank you in advance and all the best
Lucas
- Dominant language
- C
- Stars
- 950
- Forks
- 475
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 11
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from samtools/htslib
-
Difficulty 3/5 1-2 days Newbie friendliness 74/100
-
Difficulty 3/5 1-2 days Newbie friendliness 76/100
-
tabix performance Open
Similar issues
-
[adam] AdamNet network read doesn't cap to MAX_ADAM_PACKET_LEN, overflows client receive buffers Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
FujiNetWIFI/fujinet-firmware#1649 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
HarbourMasters/Shipwright#7229 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
riscv-software-src/riscv-isa-sim#2435 · 1 comment ·
-
bug Self Built Image SNAPSHOT Supported Device target/ramips
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100