I'm automating updates on a google sheet document which comprised from various data sheets. In the Process I'm reading the updates from 'Updates' sheet. and writing them according to different rules to other sheets. Below is my code (main function which is what relevant at the moment):
function mainFunction()
{
//Lock the file while processing is done
var lock = LockService.getScriptLock();
lock.tryLock(15000);
var updatesSheetName ="Updates";
var updatesSheet = SpreadsheetApp.getActive().getSheetByName(updatesSheetName);
if (updatesSheet==null)
{
Logger.log("Retrieve Updates sheet:: Failure");
//TODO : how to break out of execution and report error
}
var updateDataRange = updatesSheet.getDataRange().getValues(); // Read data from 'Updates' row 0 is column names
if (updateDataRange==null)
{
Logger.log("Updates Data retrieve :: Failure");
//TODO : how to break out of execution and report error
}
Logger.log("Retrieve Updates sheet :: Succesful");
Logger.log("Updates Data Matrix retrieve :: Succesful");
var updatesDataToWrite = processData(updateDataRange); // From ExecutionMethod.gs
if (updatesDataToWrite!=null)
{
Logger.log("Processing updates data :: Succesful");
updateDataRange=updatesDataToWrite;
updateDataSheet(updateDataRange,"Updates"); // Write new Updates Matrix to 'Updates' sheet
Logger.log("Clean Updates sheet::succesfuly");
if (updateDataRange.length>1)
{
Logger.log("Not All Updates were processed : Please check Errors");
}
//updateMainSheet(); need to understand logic
}
else if (updatesDataToWrite==null)
{
Logger.log("Processing updates data :: Failure");
}
lock.releaseLock();
}
What I'm trying to figure out is how to recover/stop execution in case of failed reading of data :
updatesSheet==null
How do i stop the execution altogether ? Programmatically? I haven't found anything i can relate/use online or in the google app script reference
throwa new error