I cannot figure out why this error is being thrown at me because it is random:
SyntaxError: Unexpected token in object literal
It is part of a function that I use to grab a label from the cache. If I reload my script from start without doing anything different it will work fine. Then for some reason that I cannot find any trigger for, it will stop working at the line labels = JSON.parse(labels);
My best guess is that there is a timeout on the cache, however when I log the labels variable I don't get any difference between the two (that I have spotted).
p.s. I am also open to other methods to accomplish easily pulling the labels.
var labels = function() {
var labels = CacheService.getPrivateCache().get('labels');
if (!labels) {
labels = PropertiesService.getDocumentProperties().getProperty('labels');
CacheService.getPrivateCache().put('labels', labels, 660);
}
if (labels) {
labels = JSON.parse(labels);
} else {
// Something went wrong
Browser.msgBox("Something went wrong, please reinstall")
}
return labels;
}
function testcache() {
// var labels = this.labels();
var dropBoxLabels = this.labels().dropBoxes;
var dropBoxLabel = this.labels().dropBox;
var periodLabel = this.labels().period;
var editLabel = this.labels().edit;
var viewLabel = this.labels().view;
var teacherLabel = this.labels().teacher;
Logger.log("");
}