Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apps Script Custom Function- Internal Error

I've just started playing around with Apps Script. I opened a new spreadsheet, accessed the script editor, and wrote the following simple function:

function DOUBLES(num) {
  return num * 2;
}

I then saved the script, refreshed my browser and used my function in a cell:

=DOUBLES(1)

The correct answer (2) appeared in the cell, so I replaced my 1 argument with a 2. This is where it gets weird. Upon changing said argument, I got an #ERROR answer: "Internal error executing the custom function." When I changed the argument back to a 1, however, the error persisted. THEN, when I decided to try 2 again, I got the correct 4 response. Having tried this multiple times, refreshing/replacing my spreadsheet, and scratching my head so much I'm leaving trenches, I'm unsure as to why my function only appears to work 30-50% of the time. I've tried other cells, other argument numbers, etc. It seems a toss-up as to whether I'll end up with an answer or an error.

like image 641
whiterabbit25 Avatar asked Dec 10 '22 22:12

whiterabbit25


2 Answers

As per Google's documentation:

A custom function call must return within 30 seconds. If it does not, the cell will display an error: Internal error executing the custom function.

This was indeed my case and I after a wee bit of code optimization I reduced the occurrence of the error to 10% of the cases.

like image 113
Adelin Avatar answered Dec 25 '22 11:12

Adelin


There appears to be a recently-introduced bug in the handling of Google Apps Script custom functions.

This is apparently the subject of Issue 5222. (I say "apparently" because that issue report isn't really clear. But good enough.) Star it to get more attention on it, and to receive updates.

like image 32
Mogsdad Avatar answered Dec 25 '22 12:12

Mogsdad