Skip to content
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

Merged
merged 1 commit into from
Jul 15, 2024
Merged

Conversation

nh13
Copy link
Member

@nh13 nh13 commented May 30, 2024

Using the Io.assert* within the constructor will yield better error messages for the user.

Also added an explicit close to the input SamSource

Using the `Io.assert*` within the constructor will yield better error messages for the user.

Also added an explicit close to the input `SamSource`
@nh13 nh13 temporarily deployed to github-actions May 30, 2024 03:35 — with GitHub Actions Inactive
@nh13 nh13 temporarily deployed to github-actions May 30, 2024 03:35 — with GitHub Actions Inactive
Copy link

codecov bot commented May 30, 2024

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 95.61%. Comparing base (d5b38ca) to head (adb0693).

Files Patch % Lines
...c/main/scala/com/fulcrumgenomics/bam/SortBam.scala 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #994      +/-   ##
==========================================
- Coverage   95.62%   95.61%   -0.02%     
==========================================
  Files         126      126              
  Lines        7364     7365       +1     
  Branches      500      510      +10     
==========================================
  Hits         7042     7042              
- Misses        322      323       +1     
Flag Coverage Δ
unittests 95.61% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +63 to +64
Io.assertReadable(input)
Io.assertCanWriteFile(output)
Copy link
Contributor

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 same

Copy link
Member Author

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 ValidationExceptions, 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

val in = SamSource(input)
val out = SamWriter(output, in.header.clone(), sort=Some(sortOrder), maxRecordsInRam=maxRecordsInRam)
out ++= in
out.close()
in.safelyClose()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also a naive question, why doesn't out also take safelyClose()?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

@nh13 nh13 requested a review from tfenne July 15, 2024 21:30
@nh13 nh13 merged commit f228b32 into main Jul 15, 2024
4 of 6 checks passed
@nh13 nh13 deleted the nh13-patch-2 branch July 15, 2024 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants