Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

google apps script - "We're sorry, a server error occurred. Please wait a bit and try again" error when running a function from a custom menu

I have received 341 error notification emails for the below error

We're sorry, a server error occurred. Please wait a bit and try again.

The notification email only tells about the name of function in which the issue is occurring.

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.


Below is the function in which error is coming

function crunchEmails() {
  var sheet   = SpreadsheetApp.getActiveSheet();
  var gLabel  = sheet.getRange("gmailLabel").getValues();
   
   
  // check the current SpreadSheet for limits and create a 
  // new SpreadSheet if limits are approaching
  checkSpreadSheet();
  
  
  var gFolder = sheet.getRange("outputFolderName").getValues();
  var gSpreadSheetName = sheet.getRange("outputSpreadsheetPrefix").getValues();
  var threadsPerSearch  = sheet.getRange("threadsPerSearch").getValues(); 

  // Number of emails per search:
  var threads = GmailApp.search("-label:" + gLabel, 0, threadsPerSearch); 
  
  for (var x=0; x<threads.length; x++) {
        
    var messages = threads[x].getMessages();
    
    // getting null...a thread without messages is weird
    if(messages != null) {
     for (var y=0; y<messages.length; y++) {
        
        updateSpreadSheet(messages[y]);
       
      }
    }
   
    GmailApp.getUserLabelByName(gLabel).addToThread(threads[x]);
  }
}

I am stuck in the middle of nowhere, have no clue about why this is happening?

Could anyone please guide to resolve the issue?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Problem Solved.

The problem is with string replace function in some other function. I am using the string replace function with regular expression as input to replace function. The regular expression was incorrect due which i am getting the above error.

That's really weird, at least GAS should give some proper error.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...