-
Notifications
You must be signed in to change notification settings - Fork 6
Description
I had my sync blow up again. I'm pretty sure it's the same problem I had before, where "somehow" (not sure how) I ended up with two copies of SyncTokenFile.txt in my google drive. This messes up the script's sync.
The result is that my _Contacts_Sync spreadsheet has hundreds of thousands of duplicate "updates" in it, and the script crashes. The "fix" for this is I have to delete the triggers, delete all of my contacts from one of my sync accounts, and reinstall everything. PITA.
So, to protect the script from this problem in the future, I have added a couple of lines of code (in bold here) in between the original code (not bold). This happens in three separate places in the code:
var syncTokenFiles = DriveApp.getFilesByName(syncTokenFileName);
if (syncTokenFiles.length >1 ) {
MailApp.sendEmail({
to: statusEmail,
subject: "GAS Contacts Sync: too many synctoken files!",
htmlBody: "There is more than one syncTokenFile in your Gdrive. This will corrupt the sync. Killing the script."
})
throw ("There is more than one syncTokenFile in your Google Drive. Killing script.");
} // end IF there is more than one synctokenfile
else {
Logger.log (" Found the syncTokenFile.");
}
var syncTokenFile = syncTokenFiles.next();
(Sidebar: I sync my Google Drive to my local computer, and this very well could have something to do with how I ended up with two copies. For now, I care more about protecting the sync function than doing a forensic dive into how that occurred.)