Commit fa91c755 authored by Ian Humphrey's avatar Ian Humphrey
Browse files

Fixed ascii2isis to output error message to user instead of getting stuck. Fixes #4596.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@7461 41f8697f-d340-4b68-9986-7bafba869bb8
parent 7cc79ea8
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -116,11 +116,24 @@ void ascii2isis(Buffer &out) {
    }  
    
    fin >> out[i];

    // If we've reached the end of file and stream is bad, we didn't find enough numerical data
    if (!fin && fin.eof()) {
      QString msg = "End of file reached. There is not enough data in [" + from;
      msg += "] to fill the output cube.";
      throw IException(IException::User, msg, _FILEINFO_);
    }

    // Check if there was an issue extracting a double
    if (!fin) {
      // Clean stream to get the position and invalid data that broke the stream
      fin.clear();
      QString msg = "Could not extract non-numerical data [" + QString(fin.peek()) + "] ";
      msg += "at byte position [" + QString::number(fin.tellg()) + "]. ";
      msg += "Please make sure to skip any header data in [" + from + "].";
      throw IException(IException::User, msg, _FILEINFO_);
    }

    out[i] = TestSpecial(out[i]);
  }
}
+6 −2
Original line number Diff line number Diff line
@@ -26,10 +26,14 @@
    <change name="Steven Koechle" date="2008-08-30">
        Added ability to change special pixel ranges. Added example.
    </change>
    <change name="Makayla Shepherd" data="2015-07-15">
        Fixed a problem with non-numeric cahracters in the file which resulted ascii2isis
    <change name="Makayla Shepherd" date="2015-07-15">
        Fixed a problem with non-numeric characters in the file which resulted ascii2isis
        hanging. Fixes #2066.
    </change>
    <change name="Ian Humphrey" date="2017-03-16">
        Added an error message when the reading fails if the file header isn't skipped.
        Fixes #4596.
    </change>
  </history>


+21 −0
Original line number Diff line number Diff line
APPNAME = ascii2isis

include $(ISISROOT)/make/isismake.tsts

commands:
#   TEST A: Broken stream when not skipping header.
	echo -e "Error Test A: " > $(OUTPUT)/error_temp.txt;
	if [[ `$(APPNAME) \
	  from=$(INPUT)/input.txt \
	  to=$(OUTPUT)/output.cub \
	  lines=3 \
	  samples=3 \
	  2>> $(OUTPUT)/error_temp.txt \
	  > /dev/null` ]]; \
	then \
	  true; \
	fi;

	$(SED) 's+\[/.*/input/+\[input/+' $(OUTPUT)/error_temp.txt > $(OUTPUT)/error.txt;
	$(RM) $(OUTPUT)/error_temp.txt;
	$(RM) $(OUTPUT)/output.cub;