Description
The processTimeframe() function calls process.exit(1) in two places inside try/catch blocks (lines 321 and 374). This kills the entire Node.js process immediately, bypassing any cleanup that happens after the function returns — including the atomicWrite tmp file cleanup at the top of the main execution block.
Additionally, lines 376 has a return data; statement that is unreachable because line 374 process.exit(1) terminates the process before it can execute.
Affected Code
async function processTimeframe(sourceData, DATA_DIR, periodName, daysAgo, badgesMap) {
// ...
try {
atomicWrite(filepath, data);
console.log(`${periodName} data saved successfully`);
return data; // ← line 370 — fine
} catch (err) {
console.error(`Failed to write json file: `, err.message);
process.exit(1); // ← line 374 — kills process, line 376 never runs
}
return data; // ← line 376 — unreachable
}
Similarly on line 321:
} catch (err) {
console.error(`Failed to load previous file: `, err.message);
process.exit(1); // ← kills process on a transient file error
}
Steps to Reproduce
- Delete one of the daily snapshot files in the data directory.
- Run
node scripts/sync-leaderboard.js
- The script immediately exits with
process.exit(1) when it fails to load the previous daily file.
- The overall.json may have already been partially written, leaving data in an inconsistent state.
Expected Behavior
- Use
throw err instead of process.exit(1) so errors propagate to the top-level handler.
- The caller should handle the error, log it, and call
process.exit(1) once at the top level if needed.
- Remove the unreachable
return data; after process.exit(1).
Suggested Fix
Replace process.exit(1) with throw err in both locations inside processTimeframe():
} catch (err) {
console.error(`Failed to write json file: `, err.message);
throw err; // instead of process.exit(1)
}
And remove the unreachable return data; at line 376.
Affected Files
scripts/sync-leaderboard.js (lines 319-376)
Description
The
processTimeframe()function callsprocess.exit(1)in two places inside try/catch blocks (lines 321 and 374). This kills the entire Node.js process immediately, bypassing any cleanup that happens after the function returns — including theatomicWritetmp file cleanup at the top of the main execution block.Additionally, lines 376 has a
return data;statement that is unreachable because line 374process.exit(1)terminates the process before it can execute.Affected Code
Similarly on line 321:
Steps to Reproduce
node scripts/sync-leaderboard.jsprocess.exit(1)when it fails to load the previous daily file.Expected Behavior
throw errinstead ofprocess.exit(1)so errors propagate to the top-level handler.process.exit(1)once at the top level if needed.return data;afterprocess.exit(1).Suggested Fix
Replace
process.exit(1)withthrow errin both locations insideprocessTimeframe():And remove the unreachable
return data;at line 376.Affected Files
scripts/sync-leaderboard.js(lines 319-376)