-
Couldn't load subscription status.
- Fork 243
convert Runtime exceptions in the CRAM code into CRAMExceptions (also… #1526
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| */ | ||
| package htsjdk.samtools.cram.build; | ||
|
|
||
| import htsjdk.samtools.cram.CRAMException; | ||
| import htsjdk.samtools.cram.common.MutableInt; | ||
| import htsjdk.samtools.cram.compression.ExternalCompressor; | ||
| import htsjdk.samtools.cram.encoding.*; | ||
|
|
@@ -422,7 +423,7 @@ private EncodingDetails buildEncodingForTag(final List<CRAMCompressionRecord> re | |
| new ExternalByteArrayEncoding(tagID)).toEncodingDescriptor(); | ||
| return details; | ||
| default: | ||
| throw new IllegalArgumentException("Unknown tag type: " + (char) type); | ||
| throw new CRAMException("Unknown tag type: " + (char) type); | ||
|
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. This one does seem like an appropriate case for CRAMException. |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -468,9 +469,9 @@ static int getTagValueByteSize(final byte type, final Object value) { | |
| if (value instanceof long[]) { | ||
| return 1 + 4 + ((long[]) value).length * 4; | ||
| } | ||
| throw new RuntimeException("Unknown tag array class: " + value.getClass()); | ||
| throw new CRAMException("Unknown tag array class: " + value.getClass()); | ||
| default: | ||
| throw new RuntimeException("Unknown tag type: " + (char) type); | ||
| throw new CRAMException("Unknown tag type: " + (char) type); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,13 +19,15 @@ | |
|
|
||
| import htsjdk.samtools.SAMFileHeader; | ||
| import htsjdk.samtools.SAMTextHeaderCodec; | ||
| import htsjdk.samtools.cram.CRAMException; | ||
| import htsjdk.samtools.cram.common.CramVersions; | ||
| import htsjdk.samtools.cram.common.CRAMVersion; | ||
| import htsjdk.samtools.cram.structure.*; | ||
| import htsjdk.samtools.util.FileExtensions; | ||
| import htsjdk.samtools.util.Log; | ||
| import htsjdk.samtools.util.RuntimeIOException; | ||
|
|
||
| import javax.security.auth.login.CredentialException; | ||
| import java.io.*; | ||
| import java.nio.ByteBuffer; | ||
| import java.nio.ByteOrder; | ||
|
|
@@ -88,7 +90,7 @@ public static long writeCramEOF(final CRAMVersion cramVersion, final OutputStrea | |
| throw new RuntimeIOException(e); | ||
| } | ||
|
|
||
| throw new IllegalArgumentException(String.format("Unrecognized CRAM version %s", cramVersion)); | ||
| throw new CRAMException(String.format("Unrecognized CRAM version %s", cramVersion)); | ||
|
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. This one is borderline, but I'd err on leaving it as IllegalArgumentException, or else RuntimeException. |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -123,13 +125,13 @@ public static CramHeader readCramHeader(final InputStream inputStream) { | |
| try { | ||
| for (final byte magicByte : CramHeader.MAGIC) { | ||
| if (magicByte != inputStream.read()) { | ||
| throw new RuntimeException("Input does not have a valid CRAM header."); | ||
| throw new CRAMException("Input does not have a valid CRAM header."); | ||
| } | ||
| } | ||
|
|
||
| final CRAMVersion cramVersion = new CRAMVersion(inputStream.read(), inputStream.read()); | ||
| if (!CramVersions.isSupportedVersion(cramVersion)) { | ||
| throw new RuntimeException(String.format("CRAM version %s is not supported", cramVersion)); | ||
| throw new CRAMException(String.format("CRAM version %s is not supported", cramVersion)); | ||
| } | ||
|
|
||
| final CramHeader header = new CramHeader(cramVersion, null); | ||
|
|
||
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.
I'm not sure what the original intent of CRAMException was, but starting with the CRAM rewrite I restricted it's use to internal error conditions, such as malformed input as reported in broadinstitute/picard#1624. Not all of the CRAM codebase is conforming yet, but I don't think this is a case where CRAMException makes sense, since this is a user error.