Skip to content

Commit 69ecb30

Browse files
authored
Errors in BAM iterator should be fatal (#265)
* Use personal hts-nim fork * Exit nonzero if iterator fails due to IO issues * Bump hts-nim dependency version * IOError -> BamError * Revert "Use personal hts-nim fork" Now that hts-nim PR is merged, we revert the commit that uses my personal fork (f337ba1), and update to the latest Nimble version. * Add comment clarifying try/except block
1 parent 52813e0 commit 69ecb30

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

mosdepth.nim

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,14 @@ iterator regions(bam: hts.Bam, region: region_t, tid: int, targets: seq[
181181
if tid != -1:
182182
if stop == 0:
183183
stop = targets[tid].length
184-
for r in bam.query(tid, int(region.start), int(stop)):
185-
yield r
184+
try:
185+
for r in bam.query(tid, int(region.start), int(stop)):
186+
yield r
187+
# if the iterator fails due to an invalid read from the BAM (due to file
188+
# corruption or filesystem issues), we want to gracefully exit with a
189+
# nonzero return.
190+
except hts.BamError:
191+
quit getCurrentExceptionMsg()
186192
else:
187193
stderr.write_line("[mosdepth]", region.chrom, " not found")
188194

mosdepth.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license = "MIT"
77

88
# Dependencies
99

10-
requires "hts >= 0.3.29", "docopt == 0.7.1", "nim >= 1.0.0", "https://github.com/brentp/d4-nim >= 0.0.5"
10+
requires "hts >= 0.3.31", "docopt == 0.7.1", "nim >= 1.0.0", "https://github.com/brentp/d4-nim >= 0.0.5"
1111

1212
bin = @["mosdepth"]
1313
skipDirs = @["tests"]

0 commit comments

Comments
 (0)