Open KemingHe opened 4 months ago
@rosera
Syntax error in lab01/importTestData.js, line 11-25. Declared err used e. In addition, e is ambiguous as it's used for both csv parsing as well as writing to db. See below.
lab01/importTestData.js
err
e
async function importCsv(csvFilename) { const parser = csv.parse({ columns: true, delimiter: ',' }, async function (err, records) { if (e) { console.error('Error parsing CSV:', e); return; } try { console.log(`Call write to Firestore`); await writeToDatabase(records); console.log(`Wrote ${records.length} records`); } catch (e) { console.error(e); process.exit(1); } }); await fs.createReadStream(csvFilename).pipe(parser); }
See open PR (number to be added):
pErr
ioErr
forEach
for...of
importTestData.js
async function importCsv(csvFilename) { const parser = csv.parse( { columns: true, delimiter: ',' }, async function (pErr, records) { // Gracefully handle parsing errors. if (pErr) { console.error('Error parsing CSV:', pErr); return; } try { console.log(`Call write to Firestore`); await writeToDatabase(records); console.log(`Wrote ${records.length} records`); // Gracefully handle database errors. } catch (ioErr) { console.error(ioErr); process.exit(1); } } ); await fs.createReadStream(csvFilename).pipe(parser); }
Linked PR is #65
Bug Report and Fix PR
@rosera
Description
Syntax error in
lab01/importTestData.js
, line 11-25. Declarederr
usede
. In addition,e
is ambiguous as it's used for both csv parsing as well as writing to db. See below.Location
Proposed Solution
See open PR (number to be added):
pErr
for parsing error, andioErr
for database error.forEach
intofor...of
for best ES6+ practices.importTestData.js
as well.Solution Code