Skip to first unread message

Andrew Apell

unread,
Oct 1, 2019, 2:25:19 AM10/1/19
to google-apps-sc...@googlegroups.com
getEffectiveUser() is suddenly throwing an error for me and I cannot figure out why. Previously the function was working well then, out of no where, this error surfaces.

Here is the scenario:

function myFunction {
try{
var email = Session.getEffectiveUser().getEmail();
// Other stuff
} Catch..
}


When I run this google.script.run.withSuccessHandler(onSuccess).myFunction() from the html side, it works well but when I call myFunction from the server side, my custom function simply returns Exception.
Permissions are OK, scopes are OK... everything else seems fine except this.

What should I do?

EDIT:

When I remove try...catch like this

function myFunction {
var email = Session.getEffectiveUser().getEmail();
// Other stuff
}


I get this error: "You do not have permission to call getEffectiveUser"

Andrew Apell

unread,
Oct 1, 2019, 3:30:01 AM10/1/19
to google-apps-sc...@googlegroups.com
What is very strange that all this working well for all custom functions (despite what the documentation might imply) and then it stopped without me doing anything.

Even weirder is the fact that it is only one function that relies on myFunction that is throwing this error.
The rest are calling myFunction without issue.

Alan Wells

unread,
Oct 1, 2019, 8:40:56 AM10/1/19
to Google Apps Script Community
Maybe you thought it was working, but it wasn't because the error was being caught.  When the error is caught, then whatever called the function continues to run.  So, the success handler would have run, even if there was an error and it was caught.  I'm not saying that is 100% guaranteed the case, but you need to consider it as a possibility.
If Apps Script suddenly has a bug, then you'd need to prove it, and then report it.  But, make sure it's actually a bug, before you report it.
Also, code run from the script editor and code triggered to run from outside the script editor can run under different permissions.

Andrew Apell

unread,
Oct 11, 2019, 3:39:56 AM10/11/19
to google-apps-sc...@googlegroups.com
I think you are right. I might have assumed that it was working when it wasn't. I decided to get a workaround since getting emails from custom functions is inconsistent.
Reply all
Reply to author
Forward
0 new messages