Skip to content

Commit

Permalink
Merge pull request #291 from conveyal/silence-number-warnings
Browse files Browse the repository at this point in the history
Silence number excessive parse exceptions logs
  • Loading branch information
evansiroky authored Sep 30, 2020
2 parents 6aa4292 + ca35e25 commit acdac77
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/main/java/com/conveyal/gtfs/error/NewGTFSError.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.conveyal.gtfs.loader.Table;
import com.conveyal.gtfs.model.Entity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -15,7 +17,7 @@
* We instead use an enum with final fields for severity and affected entity type.
*/
public class NewGTFSError {

private static final Logger LOG = LoggerFactory.getLogger(NewGTFSError.class);
/** The class of the table in which the error was encountered. */
public Class<? extends Entity> entityType;

Expand Down Expand Up @@ -111,15 +113,23 @@ public NewGTFSError setEntityId(String entityId) {
return this;
}

// Builder to add entity sequence info from string (values during load stage are passed in as strings from csv
// reader)
/**
* Builder to add entity sequence info from string (values during load stage are passed in as strings from csv
* reader).
*/
public NewGTFSError setSequence(String sequenceAsString) {
try {
// Parse int from string value found during load stage.
this.entitySequenceNumber = Integer.parseInt(sequenceAsString);
} catch (NumberFormatException e) {
e.printStackTrace();
if (sequenceAsString == null || sequenceAsString.isEmpty()) {
// Skip parsing of value if null or empty string literal.
this.entitySequenceNumber = null;
} else {
// Otherwise, attempt to parse value.
try {
// Parse int from string value found during load stage.
this.entitySequenceNumber = Integer.parseInt(sequenceAsString);
} catch (NumberFormatException e) {
LOG.warn("Could not parse int for value: '{}'", sequenceAsString);
this.entitySequenceNumber = null;
}
}
return this;
}
Expand Down

0 comments on commit acdac77

Please sign in to comment.