Add file name to exception messages #750

Merged
merged 1 commit into from Nov 23, 2016

Conversation

Projects
None yet
4 participants
Contributor

ronlevine commented Nov 22, 2016

Description

Implements #747.
Added file name to exception messages so they are more informative.

Checklist

  • Code compiles correctly
  • New tests covering changes and new functionality
  • All tests passing
  • Extended the README / documentation, if necessary
  • Is not backward compatible (breaks binary or source compatibility)

yfarjoun was assigned by ronlevine Nov 22, 2016

Contributor

ronlevine commented Nov 22, 2016

@yfarjoun Please review.

Coverage Status

Coverage increased (+0.01%) to 70.0% when pulling 0e3b250 on rhl_truncated_file_name_747 into 55c0ca8 on master.

@yfarjoun

Thanks for the extra verbiage, and tests!

@@ -283,7 +288,8 @@ public int read(final byte[] buffer, int offset, int length)
public void seek(final long pos)
throws IOException {
if (mFile == null) {
- throw new IOException("Cannot seek on stream based file");
+
+ throw new IOException("Cannot seek on stream based file " + mFile.getSource());
@yfarjoun

yfarjoun Nov 22, 2016

Contributor

might as well test this too.

@ronlevine

ronlevine Nov 22, 2016

Contributor

Done. Cannot get the mFile path since mFile is null. The path is not accessible form mStream.

@@ -302,7 +308,7 @@ public void seek(final long pos)
}
if (uncompressedOffset > available ||
(uncompressedOffset == available && !eof())) {
- throw new IOException("Invalid file pointer: " + pos);
+ throw new IOException("Invalid file pointer: " + pos + " for " + mFile.getSource());
@yfarjoun

yfarjoun Nov 22, 2016

Contributor

if you could simulate this and test it, it would be great!

Contributor

ronlevine commented Nov 22, 2016 edited

@yfarjoun Responded to comments plus did some code cleanup. Please review. Note that I have not squashed/rebased.

Coverage Status

Coverage increased (+0.01%) to 70.0% when pulling 02927b6 on rhl_truncated_file_name_747 into 55c0ca8 on master.

@yfarjoun

minor comments. thanks.

@@ -77,10 +80,81 @@ public void testBasic() throws Exception {
}
@Test
- public void testOverflow() throws Exception {
+ public void testTruncatedFile() throws Exception {
@yfarjoun

yfarjoun Nov 22, 2016

Contributor

these tests have very similar structure, could you refactor them into a single test with a DataProvider?

@ronlevine

ronlevine Nov 23, 2016

Contributor

Done.

@@ -77,10 +80,81 @@ public void testBasic() throws Exception {
}
@Test
- public void testOverflow() throws Exception {
+ public void testTruncatedFile() throws Exception {
+ final File f = new File("src/test/resources/htsjdk/tribble/vcfexample.vcf.truncated.gz");
@yfarjoun

yfarjoun Nov 22, 2016

Contributor

extract "src/test/resources/htsjdk/tribble/" as a local private static

@ronlevine

ronlevine Nov 23, 2016

Contributor

Done.

Contributor

ronlevine commented Nov 23, 2016

@yfarjoun Refactored tests using a Dataprovider and make a static final variable for the resources directory. Please review.

Coverage Status

Coverage increased (+0.02%) to 70.007% when pulling f253feb on rhl_truncated_file_name_747 into 55c0ca8 on master.

Coverage Status

Coverage increased (+0.02%) to 70.007% when pulling f253feb on rhl_truncated_file_name_747 into 55c0ca8 on master.

@vdauwera

Minor tweaks to text

@@ -50,6 +50,13 @@
* c.f. http://samtools.sourceforge.net/SAM1.pdf for details of BGZF format
*/
public class BlockCompressedInputStream extends InputStream implements LocationAware {
+
+ public final static String INCORRECT_HEADER_SIZE_MSG = "Incorrect header size for ";
@vdauwera

vdauwera Nov 23, 2016

Contributor

"Incorrect header size for file: "

@ronlevine

ronlevine Nov 23, 2016

Contributor

Done.

+
+ public final static String INCORRECT_HEADER_SIZE_MSG = "Incorrect header size for ";
+ public final static String UNEXPECTED_BLOCK_LENGTH_MSG = "Unexpected compressed block length: ";
+ public final static String PREMATURE_END_MSG = "Premature end of ";
@vdauwera

vdauwera Nov 23, 2016

Contributor

"Premature end of file: " to match pattern of other messages

@ronlevine

ronlevine Nov 23, 2016

Contributor

Done

+ public final static String INCORRECT_HEADER_SIZE_MSG = "Incorrect header size for ";
+ public final static String UNEXPECTED_BLOCK_LENGTH_MSG = "Unexpected compressed block length: ";
+ public final static String PREMATURE_END_MSG = "Premature end of ";
+ public final static String CANNOT_SEEK_STREAM_MSG = "Cannot seek on stream based file ";
@vdauwera

vdauwera Nov 23, 2016

Contributor

"Cannot seek on stream based file: "

@ronlevine

ronlevine Nov 23, 2016 edited

Contributor

Don't want a colon because this message will not be followed by a file name, the file name is not accessible from the stream. I will remove the last space in the string.

@vdauwera

vdauwera Nov 23, 2016

Contributor

oh ok

@yfarjoun

I'm happy now. please respond to @vdauwera but 👍 from me. Thanks.

Contributor

vdauwera commented Nov 23, 2016

👍 rebase and merge away

@ronlevine ronlevine Add file name to exception messages
a1e31b5

Coverage Status

Coverage increased (+0.003%) to 70.007% when pulling a1e31b5 on rhl_truncated_file_name_747 into 24c65a1 on master.

Coverage Status

Coverage increased (+0.003%) to 70.007% when pulling a1e31b5 on rhl_truncated_file_name_747 into 24c65a1 on master.

@ronlevine ronlevine merged commit de27f18 into master Nov 23, 2016

3 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.01%) to 70.013%
Details

ronlevine deleted the rhl_truncated_file_name_747 branch Nov 23, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment