Server error, google.script.run fails when using a shared library -
i have 2 google apps script projects, both of spreadsheet type.
let's call 1 server , other client.
i want expose functions server can call them client.
libraries seem perfect this.
unfortunately when add server library client using resources --> libraries... menu option, stuff breaks.
note, though server library added client, never use server library functions. (in fact server code.gs totally blank.)
server code.gs
//nothing, totally blank, these test projects created find out wrong
client code.gs
//this our entry point //it instantiates sidebar sidebar.html function test() { spreadsheetapp.getui().showsidebar(htmlservice.createhtmloutputfromfile('sidebar') .setsandboxmode(htmlservice.sandboxmode.iframe)); } function testreturn() { logger.log("dotest() called"); return 1; }
client sidebar.html
<script> function yay(d) { alert('yay: ' + d); } function boo(d) { alert('boo: ' + d); } google.script.run.withfailurehandler(boo).withsuccesshandler(yay).testreturn(); </script>
what supposed happen:
we call client.test().
this opens sidebar sidebar.html
the sidebar runs:
google.script.run.withfailurehandler(boo).withsuccesshandler(yay).testreturn();
this should call
testreturn()
client code.gsand when
testreturn()
finishes (or doesn't)...either
yay(d)
orboo(d)
should called.
very simple...
so when have no library attached, yay(d)
called! (with d = 1
in case)
but when do have library attached, boo(d)
called with
d = scripterror: we're sorry, server error occurred. please wait bit , try again.
also, believe testreturn()
never run because not show in logs.
what doing wrong? bug on google's side?
i made test projects public:
to summarize, not understand why adding shared library breaks google.script.run
.... functionality. because library blank.
tl;dr "library" spreadsheet-contained script. use stand-alone script library, , you'll fine.
i created script & library example code, , worked perfectly. grabbed copies of shared files, both spreadsheets, , reproduced error:
we're sorry, server error occurred. please wait bit , try again.
i tried couple of well-known public libraries, sheetconverter , betterlog. if removed library project, well.
observation: problem not presence of a library, it's presence of your library.
what's special library, compared hand-rolled copy of , 2 public libraries? yours spreadsheet-contained. 3 others stand-alone.
conclusion: don't that. libraries, use stand-alone scripts.
i haven't found spelled out in current documentation. happens, libraries stand-alone scripts, i've never run limitation before, , can't whether it's new or if older documentation or examples expressed stand-alone requirement.
about other questions / problems...
and when
testreturn()
finishes (or doesn't)...wrt "or doesn't" part...
failurehandler
invoked when server functionthrow
s exception. error message you've observed 1 such exception. if purposely want invokefailurehandler
, server code shouldthrow
.also, believe
testreturn()
never run because not show in logs.the editor's log viewer not accessible triggered scripts, should consider using betterlog library write logs spreadsheet. works trigger functions , web apps have no attached debugger. (just saying, because lack of log cannot reliably imply function called client code did not run.)
Comments
Post a Comment