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

Update error message for truncated file #570

Merged
merged 2 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ POSSIBILITY OF SUCH DAMAGE.
<dependency>
<groupId>gov.nasa.pds</groupId>
<artifactId>pds4-jparser</artifactId>
<version>2.3.1</version>
<version>2.4.0-SNAPSHOT</version>
Copy link
Contributor

Choose a reason for hiding this comment

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

Critical Vulnerability:

maven : gov.nasa.pds/pds4-jparser : 2.4.0-SNAPSHOT

1 Critical, 0 High, 1 Medium, 0 Low vulnerabilities have been found across 2 dependencies.
View the Lift console for details about these vulnerabilities.


ℹ️ Learn about @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

<scope>compile</scope>
<exclusions>
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public boolean isApplicable(String location) {
public void validate() throws MalformedURLException, URISyntaxException {
int objectCounter = 0;
Label label = null;
String objectIdentifier = "";
try {
URL target = getTarget();
String targetFileName = target.toString().substring(target.toString().lastIndexOf("/") + 1);
Expand All @@ -53,6 +54,7 @@ public void validate() throws MalformedURLException, URISyntaxException {

URL previousDataFile = null;
for (DataObject obj : label.getObjects()) {
objectIdentifier = getObjectIdentifier(obj);
LOG.debug("Checking DataObject #{} '{}'", objectCounter, obj.getName());

// reset counters and everything if we are onto a new datafile
Expand Down Expand Up @@ -101,7 +103,8 @@ public void validate() throws MalformedURLException, URISyntaxException {
// this was thrown by label.getDataObjects(), and means we won't perform validation for this
// product
} catch (InvalidTableException e) {
String msg = "Data Object #" + objectCounter + ": " + e.getMessage();
String msg =
"Data Object #" + objectCounter + " (" + objectIdentifier + "): " + e.getMessage();
getListener().addProblem(new ValidationProblem(
new ProblemDefinition(ExceptionType.ERROR, ProblemType.TABLE_DEFINITION_PROBLEM, msg),
getTarget(), objectCounter, -1));
Expand All @@ -110,13 +113,15 @@ public void validate() throws MalformedURLException, URISyntaxException {
} catch (FileNotFoundException e) {
// File not found. This is caught and error is tracked elsewhere
} catch (Exception e) {
String msg =
"Data Object #" + objectCounter + " (" + objectIdentifier + "): " + e.getMessage();
getListener().addProblem(new ValidationProblem(
new ProblemDefinition(ExceptionType.ERROR, ProblemType.BAD_FIELD_READ, e.getMessage()),
getTarget(), objectCounter, -1));
new ProblemDefinition(ExceptionType.ERROR, ProblemType.BAD_FIELD_READ, msg), getTarget(),
objectCounter, -1));
// e.printStackTrace();
} finally {
if (Objects.nonNull(label))
label.close();
if (Objects.nonNull(label))
label.close();
}
}

Expand All @@ -131,5 +136,15 @@ private void checkOffset(URL target, long minimumExpected, long offset, int obje
target, objectNumber, -1));
}
}

private String getObjectIdentifier(DataObject obj) {
if (obj.getName() != null) {
return obj.getName();
} else if (obj.getLocalIdentifier() != null) {
return obj.getLocalIdentifier();
} else {
return "Identifier Not Specified";
}
}
}