5

I have read similar questions such as Error type of "We're sorry, a server error occurred. Please wait a bit and try again. " and many others, but they were specific to other types of error.


I have a Google Apps Script running and processing Gmail emails with a minute timer.

Each day I receive logs by email with We're sorry, a server error occurred. Please wait a bit and try again. (see screenshot #1 below). The problem is that:

  • there is no report of the line where the error happened, so it's hard to debug

  • it happens randomly every now and then, even if nothing happened at this precise time (there was no email to process), and 99.9% of the time, everything works without error. When there is no email to process, I can't see why this code can fail:

      var mylabel = GmailApp.getUserLabelByName('emailstoprocess'); 
      var threads = mylabel.getThreads();
      for (var i = 0; i < threads.length; i++) {
          // do something
      }
    
  • in my scripts I don't call any external API, only Gmail API, and no time-consuming loop (especially when no new email is there: the script should do nothing). How can I have control over this DEADLINE_EXCEEDED error (see screenshot #2 below)? Indeed in the dashboard, Executions page, I see: We're sorry, a server error occurred: DEADLINE_EXCEEDED.

How to avoid this DEADLINE_EXCEEDED error even if my script had did nothing at the time of the failure? Or at least how to avoid receiving notifications each day about this?

enter image description here

enter image description here

TheMaster
  • 32,296
  • 6
  • 31
  • 56
Basj
  • 29,668
  • 65
  • 241
  • 451
  • When you click on the 3 dots at the right of **Unknown**, does it produce an error or it shows the trigger? – Jose Vasquez Dec 02 '20 at 13:30
  • Although I'm not sure about the detail of `do something`, from `When there is no email to process, I can't see why this code can fail:`, if the error occurs when the length of `threads` is `0`, for example, when `if (threads.length == 0) return;` is put after the line of `var threads = mylabel.getThreads();`, what result will you obtain? – Tanaike Dec 02 '20 at 23:43
  • @JoseVasquez I tried clicking on these 3 dots, but it does not give more information. It's a time-based trigger (every minute), that works 99.9% of the time without error. It's like their server has a lag a few times a day, and then the execution is delayed... – Basj Dec 03 '20 at 16:04

1 Answers1

0

Answer

As I can see this a specific error which occurs when you are using the V8 Runtime. Given the information provided you can avoid these errors by using Rhino Runtime. This is not the ideal workaround but there's not more information to debug.

Change to Rhino Runtime

Edit your manifest file appscript.json (if you are using the new script editor go to Project Settings > mark Show "appsscript.json" manifest file in editor) and change the runtimeVersion to STABLE or DEPRECATED_ES5 which means "change it to Rhino".

If the error persists

In this case it's probably an issue in Google Apps Scripts and you should post it on the Google Issue Tracker as recommended.

Reference

Manifests

Manifest structure

Jose Vasquez
  • 1,226
  • 3
  • 12