最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Apps Script Custom Function- Internal Error - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question asked Jul 14, 2015 at 8:38 whiterabbit25whiterabbit25 2773 silver badges10 bronze badges 5
  • Show the full code as you might have global code – Zig Mandel Commented Jul 14, 2015 at 12:01
  • Confirmed - reproducible. @ZigMandel - the 3 lines shown is all the code needed. – Mogsdad Commented Jul 14, 2015 at 13:42
  • today ive seen several questions with custom function issues. seems something is broken in gas. – Zig Mandel Commented Jul 14, 2015 at 13:44
  • Yep - I can get the same thing with the example "Custom Functions" script and its INCREMENT() function. – Mogsdad Commented Jul 14, 2015 at 13:49
  • I just tested the code in the question and I'm not getting any errors. Are you still able to reproduce the problem? – Eric Koleda Commented Jul 14, 2015 at 21:57
Add a comment  | 

4 Answers 4

Reset to default 6

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.

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.

In case it saves someone else a bit of time tracking down the cause of this error (fairly rare in 2021):

Many (but not all) of the custom functions on a sheet I copied from another spreadsheet were returning the Internal error executing the custom function error response.

Nothing I tried** changed that behavior, and the functions are all very small/quick, so it wasn't the 30-second timeout.

What finally worked was to make a copy of the entire spreadsheet; the functions in the copy worked normally, so I just moved the original to Trash and renamed the original.

** I tried: renaming the functions & calls to them; adding & testing new functions; making a copy of the script file and removing the original file; pasting a copy of the sheet over the first copy; making a new copy of the source sheet in the target spreadsheet -- all ended up returned the same Internal error executing the custom function errors. Perhaps the copied code was still linked to the bound script in some way, but wasn't accessible?

I resolved the error by switching to the code editor and running the custom function from there once. The #ERROR Internal error executing the custom function. disappeared.

Please note that I did not have to grant any extra permissions when I run the function from the code editor, because the function does not need any.

发布评论

评论列表(0)

  1. 暂无评论