From f228b323ec237d1d901cf100a35527f445ec6f45 Mon Sep 17 00:00:00 2001 From: Nils Homer Date: Mon, 15 Jul 2024 17:58:08 -0400 Subject: [PATCH] Validate IO in SortBam to provide nicer exceptions (#994) 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 ad5d63212..e3118956c 100644 --- a/src/main/scala/com/fulcrumgenomics/bam/SortBam.scala +++ b/src/main/scala/com/fulcrumgenomics/bam/SortBam.scala @@ -63,13 +63,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() } }