Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Unexpected token

So I am running several API on the dev server and I get this very generic relatively frequently... but I have no idea how to troubleshoot it. Here is an example of the error: Unexpected token s That is basically it, sometime the letter is different, but all in all that is all I have to work with. Currently I am running the following scripts: Powercard 2.4.4 isGM .7 TokenNameNumber .3 GroupInitiative .5 MonsterHitDie - 5e version, no version information in the script, but I just pulled it from the repository this week. TokenMod .7 BuildMonster 1.2 AttributeMod - This is quite an old version of a script that Sam wrote, but I don't think it is involved as I am only using a single command from it in one location. Two scripts that I made: One is a simple health tracker that turns the token purple when bar 3 is 50%, red when bar 3 is 20%, adds the skull when they are dead. I guess it could be related, but it is pretty darn simple and straightforward. One creates some default macros, this seems unrelated as I don't reference token anywhere in the script. I am really unsure of how to go about troubleshooting this as the error message is really vague and it generally seems to occur randomly and fairly rarely (maybe once or twice a night with no consist pattern that I have seen). Anyone have any ideas?
Disable all scripts and then re-enable/save each one separately.
1424826832
The Aaron
Pro
API Scripter
Did this just start? Grab the latest version of TokenMod if you're using it. It had a bug.
1424827384
The Aaron
Pro
API Scripter
Actually, 0.7 is the latest version. If you want to PM me a link, I'll jump in and help debug.
Unexpected token usually results from a typo, missing semicolon or something. At least in my experience.
1424828121
The Aaron
Pro
API Scripter
The frustrating thing is I know I fixed this for someone a week or so ago... digging in private messages..
1424828435
The Aaron
Pro
API Scripter
Make sure there is a carriage return at the end of each of your scripts, be sure your own scripts have a ; at the end.
1424828533
The Aaron
Pro
API Scripter
OH! This is a message from JSON.parse(): <a href="http://stackoverflow.com/questions/18791718/json-p" rel="nofollow">http://stackoverflow.com/questions/18791718/json-p</a>... So, something that is parsing data is being passed an invalid JSON string.
1424828894
The Aaron
Pro
API Scripter
Of the scripts I wrote in that list, only GroupInitiative and MonsterHitDice5e use JSON.
Interesting. AttributeMod uses JSON.parse(), but only in a command that I don't execute, so I don't suspect that is the cause. isGM, TokenNameNumber, TokenMod, BuildMonster, CreateMacro (mine) and HealthTracker (mine) do not use JSON.parse(). Now I did find several cases where the semi-colon and/or carriage return were missing from the end of the script, so I corrected all of those. The MonsterHitDice5e pulls from one field for input right? I did notice that several of my creatures I input the NPC Hit Die field as [[formula]], could that be causing an issue?
Another thing I have noticed is that GroupInitiative does not seem to be maintaining it's configuration between stopping and starting the sandbox, should it be? Or is it possible that this failure is causing it to reset?
1424836939
The Aaron
Pro
API Scripter
Having [[ 2d6+8 ]] in there will work as well as having 2d6+8. It passes whatever is in there to /roll, so having an inline would just mean you were doing /r [[2d6+8]], which leads to just /r 12 which is fine. I'm starting to thing this is an API bug..
1424837333
The Aaron
Roll20 Production Team
API Scripter
Ah, found that previous instance: I do have another request.... Everything is working perfectly - except when I enable the Stephen L's script "Marching Order". When I activate that script, my output console reads "Unexpected Identifier". I just "DMed you, would you mind looking at that?? I dug into that for about 2 hours and eventually determined that I could delete the entire script and it would still give that error if it was enabled. I'll raise this to the Devs.
I've gotten the unexpected token 's' a few times as well. Usually occurs when I start a campaign that was dormant for awhile. Oddly, when I save the scripts, it simply goes away, so it doesn't appear to be a problem in syntax with the scripts.
1424837834
The Aaron
Pro
API Scripter
I'd still like to take a look at your scripts if you can PM me a join and GM me.
When this reappears (it usually will) and I also have experienced the same as Ken. It almost always appears in a campaign that has been inactive, then starting it, seems like it will pop up almost immediately.
1424839620
The Aaron
Pro
API Scripter
So, has it disappeared for you at this point?
1424846428
vÍnce
Pro
Sheet Author
Ken L. said: I've gotten the unexpected token 's' a few times as well. Usually occurs when I start a campaign that was dormant for awhile. Oddly, when I save the scripts, it simply goes away, so it doesn't appear to be a problem in syntax with the scripts. I can second this.
1424861251
Lithl
Pro
Sheet Author
API Scripter
The Aaron said: Ah, found that previous instance: I do have another request.... Everything is working perfectly - except when I enable the Stephen L's script "Marching Order". When I activate that script, my output console reads "Unexpected Identifier". I just "DMed you, would you mind looking at that?? I dug into that for about 2 hours and eventually determined that I could delete the entire script and it would still give that error if it was enabled. I'll raise this to the Devs. "Unexpected token" is an error in lexical analysis of what is expected to be a JSON string. "Unexpected identifier" is a SyntaxError from the JavaScript engine itself (often caused by a missing character or an extra character in the script).
Aaron, I could not forcibly reproduce this last night, however this morning I went to start the campaign: API sandbox shutdown due to campaign inactivity. Spinning up new sandbox... Spinning up new sandbox... Unexpected token s It is currently in this state, I will PM you a join link for the campaign. Thanks
I do find it interesting that it tried to spin up two sandboxes...
1424879713

Edited 1424885165
The Aaron
Pro
API Scripter
Ok, the issue seems to be unicode characters in the BuildMonster script: &gt; ag "[\x80-\xFF]" BuildMonster.js 80: throw("Attribut non d��fini pour la valeur " + currentVal); 161: statblock = unescape(statblock).trim().replace(/&lt;br[^&gt;]*&gt;/g, '#').replace(/(&lt;([^&gt;]+)&gt;)/ig,"").replace('���', '-') I replaced the unicode with the equivalent hexadecimal escape sequences and it seems to be running: &gt; nl -b a BuildMonster.js| grep "^\s*\(80\|161\)" 80 throw("Attribut non d \xc3\xa9 fini pour la valeur " + currentVal); 161 statblock = unescape(statblock).trim().replace(/&lt;br[^&gt;]*&gt;/g, '#').replace(/(&lt;([^&gt;]+)&gt;)/ig,"").replace(" \xe2\x80\x93 ", '-'); Scratch that, did a bit more research on Unicode (which, btw is crazy...). I updated the BuildMonster2 script to use the String.fromCharCode() function to generate the right character: &gt; nl -b a BuildMonster.js| grep "^\s*\(80\|161\)" 80 throw("Attribut non d "+String.fromCharCode(0xc3a9)+" fini pour la valeur " + currentVal); 161 statblock = unescape(statblock).trim().replace(/&lt;br[^&gt;]*&gt;/g, '#').replace(/(&lt;([^&gt;]+)&gt;)/ig,"").replace( String.fromCodeChar(0x2013) , '-'); I believe it will still work correctly, but you'll need to test it to be certain.
Ok, I will try to test it out. This script is from Jean-Francois R... maybe we should post this in his script as a potential problem?
1424889409
The Aaron
Pro
API Scripter
Interesting. I'll grab his source and see if I get the same issues.
1424920314

Edited 1424920364
The Aaron said: Ok, the issue seems to be unicode characters in the BuildMonster script: I'm not sure of this. My Script uses tons of unicode, but does not have this error. However campaigns that use other scripts do produce it (i'll have to narrow those down) when prior to the last week, or two week's updates (on the dev server) this didn't occur with those same exact scripts.
Well I am not sure about your use case Ken, but I can confirm with certainty that this problem hasn't been seen again. Double checked it now 3-4 times after system has sit for a significant period of time. I still need to validate the changes though to build-monster to make sure the script works as expected (which I am sure it will).
1424966383
The Aaron
Pro
API Scripter
To Ken's point, this has fixed the issue, but it doesn't really prove what the problem is. Glad to hear it's working though!
I updated my script. I can't find a reason why some code would parse my script to JSON....
1425054505

Edited 1425054566
Ok... this is strange, in one campaign, I get this error, and in another I don't.... With the exact same scripts loaded. The only difference is that the one this occurs in is an older campaign; the latest is a newer campaign I created about a week ago where this does not occur. (both tested with the timeout)
I have to say that this reappeared today... I will say that this only seems to appear when I start the campaign. Once I hit "Save Script" things generally stay stable through use, which is good. The only issue I have is the "in between" sessions where a player may jump on to setup a macro or powercard and the API falls down. If I am not available to restart it, they are pretty much stuck waiting until I can login to do that.
1425056475

Edited 1425056504
Try making a new campaign, copy those scripts over, and let me know if you still see the issue after leaving it to idle, then returning to it. I'm wondering if it is somehow tied to the new set of dev updates. I only noticed this recently in the last couple weeks or so. For me this is in the dev server, I'm unsure the status of the production server. But I do know that some updates were pushed to production (mostly bug-fixes).
1425057294
The Aaron
Pro
API Scripter
I've gotten this on the Dev server now too, with out Jean-Francois' script. hmm..
I can try this, however some background. I believe that this only happening on the DEV servers. I have 2 different campaigns now on DEV, one Sandbox for the API, then this actual campaign that I have been running. The problem occurs on both. This one was created a week or two after the original Sandbox. I have many campaigns that run the same scripts (older version of Powercard is the exception), I haven't seen this problem there (personally).
Kevin said: I do find it interesting that it tried to spin up two sandboxes... Checked again I can confirm that it tries to spin up two sandboxes before it pops this out.
Each time I have seen this message it always tries to spin up 2 sandboxes prior to failing with the error.
1425072844
The Aaron
Pro
API Scripter
Riley told me that the double message doesn't actually indicate spinning up to sandboxes. Not sure what it does indicate though.
any update to this issue?
1425186095
The Aaron
Pro
API Scripter
The doubled spinning up sandbox messages are just a reporting artifact Riley needs to fix. No other update that I know of.
Not the double sandbox thing, the unexpected token s.
1425225604
The Aaron
Pro
API Scripter
The Aaron said: No other update that I know of.
Just to throw my hat into this ring as well. I get this message regularly now when starting up my campaign after being dormant a few days. Today I took all of my active scripts and used the Editley tool for Google Drive to review for errors and clean up the formatting. I then re-pasted into Roll20. I have not had the error again just yet, but since I didn't actually make any changes involving a "s" token, I suspect I will see this again soon. My suspicion is that the back-end system that is melding the individual scripts into one long script may be doing some improper concatenation involving the "s" token. Like I said, that's a just a guess. I can just spin up a new sandbox and the error goes away until next time.
1426116397
vÍnce
Pro
Sheet Author
Joshua V. said: Just to throw my hat into this ring as well. I get this message regularly now when starting up my campaign after being dormant a few days. Today I took all of my active scripts and used the Editley tool for Google Drive to review for errors and clean up the formatting. I then re-pasted into Roll20. I have not had the error again just yet, but since I didn't actually make any changes involving a "s" token, I suspect I will see this again soon. My suspicion is that the back-end system that is melding the individual scripts into one long script may be doing some improper concatenation involving the "s" token. Like I said, that's a just a guess. I can just spin up a new sandbox and the error goes away until next time. Same experience. I ran my scripts thru the google's js checker as well, but I still get the error occasionally.
1426262281

Edited 1426262651
Julien
Translator
I do experience the same issue when we start playing (Unexpected token s). But after I save any script to re-spin up the sandbox, everything's fine.
1426263167
Ziechael
Forum Champion
Sheet Author
API Scripter
Julien said: I do experience the same issue when we start playing (Unexpected token s). But after I save any script to re-spin up the sandbox, everything's fine. Ditto... with no scripts affected (seemingly) during play
My last session was two weeks ago and when I started up the campaign last night I had this error again. I started it up again just now and had the same error. Saving still clears it, but it's getting annoying.
I'm in the same boat, and also resolve it by saving and restarting the sandbox.
This is indeed still impacting me as well. It isn't a huge deal for me personally because I can just restart the sandbox. The problem though is that my players may join to update their characters in between sessions and because the sheet we use relies on the API, if it is down they may not be able to test their updates properly, so there is a functional impact felt, even if there is a simple way to work around the problem.
When I got this error, i add an empty line at the beginning of each script in the campain. That's alway corrected the bug for me. It's like all the script are joined together without line break between...
1427123404

Edited 1427123418
I just did this, saved the sandbox, closed it and opened the campaing - the error appeared and all of my space-lines were gone.
Yeah, I was just troubleshooting this... it's strange because after saving the script it actually starts adding weird spaces in all of the other scripts.... Now I had added a line to the end of the scripts previously but this error still appears.
1427124132
Ziechael
Forum Champion
Sheet Author
API Scripter
Got excited and did this to my scripts also to try and get rid of the annoying 'unexpected token s' error... and got the same fail result :'( OK, so It's not the worst issue in the world since a 'save' allows the scripts to run as normal but hey, i'm lazy, that 1 click could be used for something else... like typing one of these characters i've used with this longwinded explanation of my laziness...