Make stream seek error message informative #927

Merged
merged 1 commit into from Jul 5, 2017

Conversation

Projects
None yet
4 participants
Contributor

ronlevine commented Jul 3, 2017 edited

Description

Fixes #819.

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)

ronlevine self-assigned this Jul 3, 2017

ronlevine requested a review from yfarjoun Jul 3, 2017

Contributor

ronlevine commented Jul 3, 2017

@yfarjoun Please review.

codecov-io commented Jul 3, 2017 edited

Codecov Report

Merging #927 into master will increase coverage by 0.014%.
The diff coverage is 100%.

@@               Coverage Diff               @@
##              master      #927       +/-   ##
===============================================
+ Coverage     65.118%   65.132%   +0.014%     
- Complexity      7278      7281        +3     
===============================================
  Files            528       528               
  Lines          31971     31975        +4     
  Branches        5468      5469        +1     
===============================================
+ Hits           20819     20826        +7     
+ Misses          8995      8994        -1     
+ Partials        2157      2155        -2
Impacted Files Coverage Δ Complexity Δ
...sjdk/samtools/util/BlockCompressedInputStream.java 75% <100%> (+1.119%) 79 <7> (+2) ⬆️
...a/htsjdk/samtools/cram/encoding/rans/Decoding.java 85.714% <0%> (+3.571%) 12% <0%> (+1%) ⬆️
Contributor

yfarjoun commented Jul 4, 2017

I don't understand the claim that this is a more informative error message. this exception is thrown when mFile == null which could mean many things...it could be that the stream has been closed, or it could be that the input stream is non-seekable...

Contributor

magicDGS commented Jul 4, 2017

@yfarjoun, do you think that the solution in the following branch is better?: https://github.com/magicDGS/htsjdk/tree/dgs_fix_819

If so, feel free to use it, @ronlevine!

Contributor

ronlevine commented Jul 4, 2017

Thanks @magicDGS. That makes the error more specific.

Contributor

ronlevine commented Jul 4, 2017

@yfarjoun @magicDGS I made the messages more specific. Please take a look. Sorry for the initial incomplete PR, I was having 2fa issues yesterday and didn't realize that my final commit did not make it's way to the origin.

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

magicDGS Jul 4, 2017

Contributor

This is a non-backwards compatible change... is it really needed?

@ronlevine

ronlevine Jul 4, 2017

Contributor

It's a clearer name but you're right, it's breaks backward compatibility and is not really need. I will revert the name.

@yfarjoun

yfarjoun Jul 5, 2017

Contributor

you didn't revert the name change.

@ronlevine

ronlevine Jul 5, 2017

Contributor

I did, it's on the line below. This is the new one. I can reverse the order to make the diff easier to view.

public final static String INVALID_FILE_PTR_MSG = "Invalid file pointer: ";
private InputStream mStream = null;
+ private boolean mIsClosed = false;
@magicDGS

magicDGS Jul 4, 2017

Contributor

Are there other cases where mIsClosed could be used? If so, the CANNOT_SEEK_CLOSED_STREAM_MSG could be re-named to CLOSED_STREAM_MSG and use the String "Closed stream error: ". Then, inside the seek() method, the message could add the "cannot seek a position".

@ronlevine

ronlevine Jul 4, 2017 edited

Contributor

Good idea. The generalized message can be used in readLine and read. But, for testing purposes, it should be the base message.

@ronlevine

ronlevine Jul 4, 2017

Contributor

On second thought, I cannot find an application for generalized version of this error message. The logic of readLine and read handle the closed condition appropriately. I added tests to demonstrate this is the case.

*/
public void seek(final long pos) throws IOException {
+ // Must be before the mFile == null check because mFile == null for closed files and streams
+ if (mIsClosed) {
+ throw new IOException(CANNOT_SEEK_CLOSED_STREAM_MSG);
@magicDGS

magicDGS Jul 4, 2017

Contributor

Maybe a simple test could be added for this codepath...

@ronlevine

ronlevine Jul 4, 2017

Contributor

Done.

Contributor

ronlevine commented Jul 4, 2017

@magicDGS Responded to your comments. Please take a look.

Contributor

magicDGS commented Jul 5, 2017

Looks good to me. Maybe @yfarjoun have more comments...

Contributor

ronlevine commented Jul 5, 2017

@yfarjoun Any more comments?

@yfarjoun

just the name-change.

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

yfarjoun Jul 5, 2017

Contributor

you didn't revert the name change.

@ronlevine ronlevine Make stream seek error message informative
ee362e5

@ronlevine ronlevine merged commit 1cd23da into master Jul 5, 2017

5 checks passed

codecov/changes No unexpected coverage changes found.
Details
codecov/patch 100% of diff hit (target 65.118%)
Details
codecov/project 65.132% (+0.014%) compared to 7d31bc2
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

ronlevine deleted the rhl_closed_feature_reader_err_819 branch Jul 5, 2017

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