-
-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate IO in SortBam to provide nicer exceptions #994
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,13 +59,15 @@ | |
@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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also a naive question, why doesn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is that we care that the output files are closed, but do not want the tool to fail/crash/except when we're cleaning up resources after the main effort of the tool has completed, so we do not propagate errors during closing inputs in this case. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naive question, what changes when these are moved to the constructor/class body?
Since the constructor doesn't do anything else, and nothing happens in
execute
before the assert, I would have thought that asserting at either location would be functionally the sameThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exceptions in the constructor are
ValidationException
s, and any exceptions (typically validation errors of the arguments) are nicely formatted on the command line, versus a huge stacktrace. And it will print out the usage too. But none of those things will happen when running the tool