Skip to content

Commit

Permalink
Merge pull request #719 from ashitsalesforce/master
Browse files Browse the repository at this point in the history
debug messages to help troubleshoot CSV issues
  • Loading branch information
ashitsalesforce authored Jul 9, 2023
2 parents 1cb67fb + 8e1b26b commit 301e5d9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
34 changes: 26 additions & 8 deletions src/main/java/com/salesforce/dataloader/dao/csv/CSVFileReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,15 @@ public CSVFileReader(File file, Config config, boolean custDelimiter) {
if (custDelimiter) {
if (config.getBoolean(Config.CSV_DELIMETER_COMMA)) {
separator.append(",");
LOGGER.debug("comma is a CSV delimiter character");
}
if (config.getBoolean(Config.CSV_DELIMETER_TAB)) {
separator.append("\t");
LOGGER.debug("tab is a CSV delimiter character");
}
if (config.getBoolean(Config.CSV_DELIMETER_OTHER)) {
separator.append(config.getString(Config.CSV_DELIMETER_OTHER_VALUE));
LOGGER.debug("CSV delimiter character: \"" + config.getString(Config.CSV_DELIMETER_OTHER_VALUE) + "\"");
}
} else {
separator.append(",");
Expand Down Expand Up @@ -189,11 +192,16 @@ record = csvReader.nextRecord();
String errMsg = Messages.getFormattedString("CSVFileDAO.errorRowTooLarge", new String[]{
String.valueOf(currentRowNumber), String.valueOf(record.size()), String.valueOf(headerRow.size())});
throw new DataAccessRowException(errMsg);
}
if (record.size() < headerRow.size()) {
} else if (record.size() < headerRow.size()) {
String errMsg = Messages.getFormattedString("CSVFileDAO.errorRowTooSmall", new String[]{
String.valueOf(currentRowNumber), String.valueOf(record.size()), String.valueOf(headerRow.size())});
throw new DataAccessRowException(errMsg);
} else {
LOGGER.debug(Messages.getFormattedString("CSVFileDAO.debugMessageRowSize",
new String[] {
String.valueOf(currentRowNumber), String.valueOf(record.size())
}
));
}

Row row = new Row(record.size());
Expand Down Expand Up @@ -248,6 +256,10 @@ private void readHeaderRow() throws DataAccessObjectInitializationException {
LOGGER.error(Messages.getString("CSVFileDAO.errorHeaderRow"));
throw new DataAccessObjectInitializationException(Messages.getString("CSVFileDAO.errorHeaderRow"));
}
LOGGER.debug(Messages.getFormattedString(
"CSVFileDAO.debugMessageHeaderRowSize", headerRow.size()));

LOGGER.info("Columns in CSV header = " + headerRow.size());
} catch (IOException e) {
String errMsg = Messages.getString("CSVFileDAO.errorHeaderRow");
LOGGER.error(errMsg, e);
Expand All @@ -270,12 +282,16 @@ private void initalizeInput(char[] csvDelimiters) throws DataAccessObjectInitial
|| StandardCharsets.UTF_16LE.name().equals(encoding)
|| "UTF-32LE".equals(encoding)
|| "UTF-32BE".equals(encoding)) {
BOMInputStream bomInputStream = new BOMInputStream(input,
ByteOrderMark.UTF_8,
ByteOrderMark.UTF_16LE,
ByteOrderMark.UTF_16BE,
ByteOrderMark.UTF_32LE,
ByteOrderMark.UTF_32BE);
BOMInputStream bomInputStream =
BOMInputStream.builder()
.setFile(file)
.setByteOrderMarks(ByteOrderMark.UTF_8,
ByteOrderMark.UTF_16LE,
ByteOrderMark.UTF_16BE,
ByteOrderMark.UTF_32LE,
ByteOrderMark.UTF_32BE)
.setInclude(false)
.get();
csvReader = new CSVReader(bomInputStream, encoding, csvDelimiters);
} else {
csvReader = new CSVReader(input, encoding, csvDelimiters);
Expand All @@ -291,6 +307,8 @@ private void initalizeInput(char[] csvDelimiters) throws DataAccessObjectInitial
String errMsg = Messages.getString("CSVFileDAO.errorUnsupportedEncoding");
LOGGER.error(errMsg, e);
throw new DataAccessObjectInitializationException(errMsg, e);
} catch (IOException e) {
throw new DataAccessObjectInitializationException(e);
} finally {
if (csvReader == null) {
IOUtils.closeQuietly(input);
Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ CSVFileDAO.errorUnsupportedEncoding=Unsupported Encoding. Open operation failed
CSVFileDAO.errorHeaderRow=Error getting header row from the CSV file.
CSVFileDAO.errorOpenNoHeaderRow=Error opening CSV file for writing: header row (with column names) has to be provided
CSVFileDAO.errorInitializing=Initialization of CSV FAILED.
CSVFileDAO.errorRowTooLarge=Error reading row #{0}: the number of data columns ({1}) exceeds the number of columns in the header ({2})
CSVFileDAO.errorRowTooSmall=Error reading row #{0}: the number of data columns ({1}) is less than the number of columns in the header ({2})
CSVFileDAO.errorRowTooLarge=Error reading data row #{0}: the number of columns ({1}) exceeds the number of columns in the header ({2})
CSVFileDAO.errorRowTooSmall=Error reading data row #{0}: the number of columns ({1}) is less than the number of columns in the header ({2})
CSVFileDAO.debugMessageRowSize=Data row #{0}: number of columns = {1}
CSVFileDAO.debugMessageHeaderRowSize=Header row: number of columns = {0}

ProcessConfig.loadingConfig=Loading process configuration from config file: {0}
ProcessConfig.errorNoProcess=Error loading process: {0} configuration from config file: {1}
Expand Down

0 comments on commit 301e5d9

Please sign in to comment.