From adb06939b405e9aed07084a461663a3a3730c6d2 Mon Sep 17 00:00:00 2001 From: Nils Homer Date: Wed, 29 May 2024 23:35:26 -0400 Subject: [PATCH] Validate IO in SortBam to provide nicer exceptions Using the `Io.assert*` within the constructor will yield better error messages for the user. Also added an explicit close to the input `SamSource` --- src/main/scala/com/fulcrumgenomics/bam/SortBam.scala | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/scala/com/fulcrumgenomics/bam/SortBam.scala b/src/main/scala/com/fulcrumgenomics/bam/SortBam.scala index 4e9a59360..573188021 100644 --- a/src/main/scala/com/fulcrumgenomics/bam/SortBam.scala +++ b/src/main/scala/com/fulcrumgenomics/bam/SortBam.scala @@ -59,13 +59,15 @@ class SortBam @arg(flag='s', doc="Order into which to sort the records.") val sortOrder: SamOrder = SamOrder.Coordinate, @arg(flag='m', doc="Max records in RAM.") val maxRecordsInRam: Int = SamWriter.DefaultMaxRecordsInRam ) extends FgBioTool with LazyLogging { + + Io.assertReadable(input) + Io.assertCanWriteFile(output) + override def execute(): Unit = { - Io.assertReadable(input) - Io.assertCanWriteFile(output) - val in = SamSource(input) val out = SamWriter(output, in.header.clone(), sort=Some(sortOrder), maxRecordsInRam=maxRecordsInRam) out ++= in out.close() + in.safelyClose() } }