Skip to content

Commit adb0693

Browse files
authored
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`
1 parent d5b38ca commit adb0693

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/main/scala/com/fulcrumgenomics/bam/SortBam.scala

+5-3
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,15 @@ class SortBam
5959
@arg(flag='s', doc="Order into which to sort the records.") val sortOrder: SamOrder = SamOrder.Coordinate,
6060
@arg(flag='m', doc="Max records in RAM.") val maxRecordsInRam: Int = SamWriter.DefaultMaxRecordsInRam
6161
) extends FgBioTool with LazyLogging {
62+
63+
Io.assertReadable(input)
64+
Io.assertCanWriteFile(output)
65+
6266
override def execute(): Unit = {
63-
Io.assertReadable(input)
64-
Io.assertCanWriteFile(output)
65-
6667
val in = SamSource(input)
6768
val out = SamWriter(output, in.header.clone(), sort=Some(sortOrder), maxRecordsInRam=maxRecordsInRam)
6869
out ++= in
6970
out.close()
71+
in.safelyClose()
7072
}
7173
}

0 commit comments

Comments
 (0)