Hi, I have written a function to validate a feed file. This function is a promise(using Bluebird) and resolves to return a hash map of all category ids. It must run twice on the same file, once to build hash map and then another time to run checks against the line of the file and the hash map to check for duplicates and to see if a category id has a valid parent id. The second time it goes through the file I'm getting an error. The error handling is very vague and doesn't say the exact issue but rather that there was an issue when reading the file. Any insight or assist would be appreciated! function validateCategoryFull(file) { //Validation Process console.log('\n\n\n --- [INFO] --- Entering category_Full function'); return new promise(function(resolve, reject){ var index = 0; var runNumber = 0; console.log('runNumber is ' + runNumber); var s = fs.createReadStream(dirPath + fileName.slice(0, -4) + "\/" + file) .pipe(es.split()) //.pipe(es.parse({error:true})) .pipe(es.mapSync(function (line) { s.pause(); if (line !== "" && index === 0 && runNumber === 0) { categoryFull.checkCategoryHeader(line, delim); } else if (line !== "" && index > 0 && runNumber === 0) { categoryFull.extractCategoryIds(index - 1, line, delim); } index++; s.resume(); }) .on('error', function () { reject(new Error('\n\n\n [Category Full] - Error while processing Promise')); }) .on('end', function () { console.log('\n\n\n[Category Full] Resolve Promise in categoryFull file.\n'); /*productFull.printLog(rowCount);*/ if (runNumber === 0){ categories = categoryFull.getAllCategoryIds(); resolve(categories); } /*console.timeEnd('Validation Excuted In');*/ }) .on('close', function() { console.log('\n\n\n --- [INFO] --- Entering category_Full 2nd time'); runNumber=1; index=1; console.log('runNumber is ' + runNumber); var r = fs.createReadStream(dirPath + fileName.slice(0, -4) + "\/" + file) .pipe(es.split()) //.pipe(es.parse({error:true})) .pipe(es.mapSync(function (line) { r.pause(); if (line !== "" && index > 0 && runNumber === 1) { categoryFull.runChecks(line, delim); categoryFullRowCount++; } index++; r.resume(); }) .on('error', function () { console.log('\n\n\n [Category Full] - Error while reading file 2nd time'); }) .on('end', function () { console.log('\n\n\n[Category Full] Read entire categoryFull file 2nd time.\n'); /*productFull.printLog(rowCount);*/ /*console.timeEnd('Validation Excuted In');*/ console.log("\n\n\n[Category Full]" + categoryFull.getErrorMessage()); }) ); }) ); }); }
Submitted July 10, 2017 at 10:05PM by TheBigTreezy
No comments:
Post a Comment