TuomoKu / SPX-GC

SPX is a graphics control client for live video productions and live streams using CasparCG, OBS, vMix, or similar software.
https://spx.graphics
MIT License
300 stars 60 forks source link

writeFile, writeTextFile and renameRundown are unsafe #93

Open Dan-Shields opened 7 months ago

Dan-Shields commented 7 months ago

All of these functions follow this pattern:

try {
    return new Promise(resolve => {
      // ... do stuff
      resolve()
    )
} catch (error) {
  logger.error('spx.writeFile - Error while saving: ' + filepath + ': ' + error);    
  return 
}

The try block will never fail, as the promise doesn't execute immediately

It should be:

return new Promise((resolve, reject) => {
  try {
    // ... do stuff
    resolve();
  } catch (error) {
    logger.error('spx.duplicateFile - Error while duplicating: ' + fileRefe + ': ' + error);    
    reject();
  }
})