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

New to API and Need Help to Trobleshoot

Listed below is the error I get while running the game.  Not sure on how to identify where the error is coming from and how to fix it. Can someone point me in the right direction? Thanks For reference, the error message generated was:  SyntaxError: Unexpected end of JSON input SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) at apiscript.js:6457:30 at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:168:1), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:168:1), <anonymous>:70:8) at TrackedObj.set (/home/node/d20-api-server/api.js:1078:14) at updateLocalCache (/home/node/d20-api-server/api.js:1421:18) at /home/node/d20-api-server/api.js:1713:7 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147) at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546)
1659326153
The Aaron
Roll20 Production Team
API Scripter
Start with listing what Mod (API) Scripts you have installed. Something that is parsing JSON is getting passed bad data. If there's nothing obvious from the list, you can try disabling them one by one until the Error goes away, then you'll know the culprit. If none of that reveals the failing script, try disabling or changing the character sheet. Character sheets also get loaded as part of the Mod Sandbox, so errors in them can show up here. 
Thanks I will start to disabling scripts
These are the scripts I have loaded  Aura/Tint HealthColors, TokenMod, Token Action Maker, HTML Builder Status Tracker, Welcome Package, Token Collisions Torch, CombatTracker ,GroupInitiative, Vector Math MatrixMath, Path Math, Character Sheet Utils, It's a Trap! - D&D 5E Generic , EncounterHelper ,  lib TokenMarkers, TokenNameNumber,  GroupCheck, Door Knocker, Apply Damage.js, UDLWindows, StatusInfo.js rumorMill.js
1659355626

Edited 1659355723
As the error occurs in apiscript.js i think that the error occurs in one of the scripts, not in the character sheets. apiscript.js is created by concatenating all your active scripts in order of the tabs into a single file.  It's some work, but you can create your own 'apiscript.js' and upload it as the only active script and then you find the exact error location. I did a quick grep on your apiscripts and there are too many that do JSON.parse to give a pointer.
Thanks for the help. I will try disabling them one at a time to see if i can locate it.
1659409030

Edited 1659409155
GiGs
Pro
Sheet Author
API Scripter
A good programming technqie is to use the half-and-half method (I don't know if it has an official title): Disable half your scripts, see if the error still occurs. If it does, you know it's in the scripts still enabled, so repeat (disable half and try again), until you get rid of the error. When the error vanishes, the error is in one of the remaining scriots, Disable everything else, and reenable those in this set. Start again, disabling half at a time... Generally speaking programming, this method finds the errors quicker than other methods. But disabling and enabling roll20 scripts is tedious, so if you don't have too many scripts, this methid might be too much trouble. Also you can have errors that only happen due to an interaction between two (or more) scripts, and this method won't find them - neither will disabling scripts one at a time, so it's not a point against it just something else to consider. PS: I'd also look at the script authors. If the script was written by Aaron, test all other scripts first. Likewise you might organise a tier of authors in your scripts. Test ones written by authors you haven't heard from before. This method will help find errors a lot faster. (It's not impossible that there's an error in a script by Aaron, or other highly regarded authors, but it's a lot less likely. Using your time wisely means checking the well-regarded authors last.)
1659456295
timmaugh
Forum Champion
API Scripter
Sometimes enabling/disabling a bunch of scripts... ...by hand... ...one at a time... ...with a sandbox reboot between... can be a pain. Another option is to look at the line number where the error is reported (in your image, that's line 6457), and see if you can narrow down which script that is. This method might not be for everyone, but it's available if you want to try. For context, your scripts get rolled up into a single js file, one script appended to the previous, so your line count starts to build. If you know that a particular script starts at line 6200 and the next script starts at 6700, then you know your erroring-line (6457) should be in the one that starts at 6200 (and the line in that script throwing the error would be 6457 - 6200 = 257). Getting the number of lines in a script can be difficult (for instance, if you installed the script from the one-click you won't see the code for those and you'll have to dig to get the line count), but here's basically what to look for: 1) Some recent script work standardizes around a way to report the starting line number of the script. When you reboot your sandbox, see if any of the scripts report an "offset"... here is one of my test games: Those numbers tell me where the scripts start, so if I see an error at line 2400, I know that's 70 lines into Fetch. Not every script (especially some of the older ones) will use this method, and typically the people using this method are fairly careful about leaving an error like this in the code, but if there are any scripts that are reporting an offset like this, it can help you track down which scripts you are NOT worried about, at the very least. 2) If you click on a script that was installed manually, you can see the actual line count by scrolling down in the code pane. You can identify manually installed scripts in the script panel because they'll be the ones without a globe beside their name in the tab list: There, libInline and SelectManager came from the 1-click. PlayMonitor is something I was writing, so I'm copying/pasting it in as I go. If I click on PlayMonitor and look in the code panel, I can scroll down and see... ...it's 40 lines long. 3) For 1-click installed scripts, you'll need to go to the Roll20 Git repo . Find the script for which you want the line count, navigate into the folder for the latest version, and click on the js file for the script. Here, you can see SelectManager has 559 lines: Caveat The one thing to be aware of using this method is that the order of tabs is not guaranteed to match the order of scripts as they are aggregated into the single JS file I mentioned. Rarely, I have seen them be out of order to how they register... and I have only seen this on high-script-count, high-line-count games (we're talking 30-40 scripts and 60K lines). I doubt whether you will see that.
Thanks everyone for your help. I will work on finding the error this week and let you know what I found.
1659490260
GiGs
Pro
Sheet Author
API Scripter
timmaugh said: Sometimes enabling/disabling a bunch of scripts... ...by hand... ...one at a time... ...with a sandbox reboot between... can be a pain. Lol, yes.
The issue seems to be with the welcome package script.
1659934762
The Aaron
Roll20 Production Team
API Scripter
GiGs said: A good programming technqie is to use the half-and-half method (I don't know if it has an official title): That's called a Binary Search.&nbsp; <a href="https://en.m.wikipedia.org/wiki/Binary_search_algorithm" rel="nofollow">https://en.m.wikipedia.org/wiki/Binary_search_algorithm</a>
1659935152
The Aaron
Roll20 Production Team
API Scripter
Hmm. I don't see any JSON references in the Welcome Package script. It could be in dependents of the script though.&nbsp; If you still want that functionality, I have a similar script called PlayerCharacters in the 1-click library. &nbsp;
Thanks I will give it a try