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
313 stars 64 forks source link

writeFile, writeTextFile and renameRundown are unsafe #93

Open Dan-Shields opened 10 months ago

Dan-Shields commented 10 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();
  }
})
TuomoKu commented 1 week ago

I will keep these here as a reminder for a future update. Thanks for pointing this out!