title: "We're sorry, a server error occurred. Please wait a bit and try again" error when running a function from a custom menu
body: <p>I have received 341 error notification emails for the below error</p>
  <blockquote>
  <p>We're sorry, a server error occurred. Please wait a bit and try again.</p>
  </blockquote>
  <p>The notification email only tells about the name of function in which the issue is occurring.</p>
  <p>The script is not running now. Any try to run any function in the script gave the above error. Also my custom menu that i have added into the Spreadsheet using the script is gone. I found no way to debug the script as every action on the script giving me the above error.</p>
  <hr />
  <p>Below is the function in which error is coming</p>
  <pre><code>function crunchEmails() {
    var sheet   = SpreadsheetApp.getActiveSheet();
    var gLabel  = sheet.getRange(&quot;gmailLabel&quot;).getValues();
     
     
    // check the current SpreadSheet for limits and create a 
    // new SpreadSheet if limits are approaching
    checkSpreadSheet();
    
    
    var gFolder = sheet.getRange(&quot;outputFolderName&quot;).getValues();
    var gSpreadSheetName = sheet.getRange(&quot;outputSpreadsheetPrefix&quot;).getValues();
    var threadsPerSearch  = sheet.getRange(&quot;threadsPerSearch&quot;).getValues(); 
  
    // Number of emails per search:
    var threads = GmailApp.search(&quot;-label:&quot; + gLabel, 0, threadsPerSearch); 
    
    for (var x=0; x&lt;threads.length; x++) {
          
      var messages = threads[x].getMessages();
      
      // getting null...a thread without messages is weird
      if(messages != null) {
       for (var y=0; y&lt;messages.length; y++) {
          
          updateSpreadSheet(messages[y]);
         
        }
      }
     
      GmailApp.getUserLabelByName(gLabel).addToThread(threads[x]);
    }
  }
  </code></pre>
  <p>I am stuck in the middle of nowhere, have no clue about why this is happening?</p>
  <p>Could anyone please guide to resolve the issue?</p>