Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added protection for duplicate syncTokenFile #18

Open
knwpsk opened this issue Dec 3, 2024 · 0 comments
Open

Added protection for duplicate syncTokenFile #18

knwpsk opened this issue Dec 3, 2024 · 0 comments

Comments

@knwpsk
Copy link

knwpsk commented Dec 3, 2024

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 tha 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 less about protecting the sync function than doing a forensic dive into how that occurred.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant