Skip to content

Commit d904b4b

Browse files
authored
Merge pull request #141 from mcode/validate-url-csv-module
Better logging in the CSVURLModule
2 parents 5b22a2d + 9c70d16 commit d904b4b

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

src/client/BaseClient.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,23 @@ class BaseClient {
4343
// Using Reduce to compute the validity of all extractors
4444
const allExtractorsValid = await this.extractors.reduce(async (curExtractorsValid, curExtractor) => {
4545
const { name } = curExtractor.constructor;
46-
4746
if (curExtractor.validate) {
4847
logger.debug(`Validating ${name}`);
49-
const isExtractorValid = await curExtractor.validate();
50-
if (isExtractorValid) {
51-
logger.debug(`Extractor ${name} PASSED CSV validation`);
52-
} else {
53-
logger.warn(`Extractor ${name} FAILED CSV validation`);
48+
try {
49+
const isExtractorValid = await curExtractor.validate();
50+
if (isExtractorValid) {
51+
logger.debug(`Extractor ${name} PASSED CSV validation`);
52+
} else {
53+
logger.warn(`Extractor ${name} FAILED CSV validation`);
54+
}
55+
return ((await curExtractorsValid) && isExtractorValid);
56+
} catch (e) {
57+
logger.warn(`Extractor ${name} could not validate. Encountered the following error: ${e.message}`);
58+
return false;
5459
}
55-
return (curExtractorsValid && isExtractorValid);
5660
}
5761
return curExtractorsValid;
58-
}, true);
62+
}, Promise.resolve(true));
5963

6064
if (allExtractorsValid) {
6165
logger.info('Validation succeeded');

src/helpers/csvParsingUtils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ function stringNormalizer(str) {
77

88
// For translating null/nil-like values into empty strings
99
function normalizeEmptyValues(data, unalterableColumns = []) {
10+
logger.debug('Checking for empty CSV values to normalize');
1011
const EMPTY_VALUES = ['null', 'nil'].map(stringNormalizer);
1112
const normalizedUnalterableColumns = unalterableColumns.map(stringNormalizer);
1213
// Flag tracking if empty values were normalized or not.

src/modules/CSVURLModule.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,20 @@ class CSVURLModule {
1616
// If data is already cached, this function does nothing
1717
async fillDataCache() {
1818
if (!this.data) {
19-
const csvData = await axios.get(this.url).then((res) => res.data);
19+
logger.debug('Filling the data cache of CSVURLModule');
20+
const csvData = await axios.get(this.url)
21+
.then((res) => res.data)
22+
.catch((e) => {
23+
logger.error('Error occurred when making a connection to this url');
24+
throw e;
25+
});
26+
logger.debug('Web request successful');
2027
// Parse then normalize the data
2128
const parsedData = parse(csvData, {
2229
columns: (header) => header.map((column) => stringNormalizer(column)),
2330
bom: true,
2431
});
32+
logger.debug('CSV Data parsing successful');
2533
this.data = normalizeEmptyValues(parsedData, this.unalterableColumns);
2634
}
2735
}

0 commit comments

Comments
 (0)