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

How to track down API errors?

Hi! Occasional I get API errors, most of the time they must originate from where I just was doing changes in the code. But sometimes this could be based on some event listener or some script updates which I just didn't notice. Regardless of the exact reason, is there any way to "understand" the error messages in order to track down the error? Of course, I know how to use the log-command to set check points, and also that I can temporarily disable scripts,but this is not always helpful. In my case, for example, I suspect one of the event listener. But my game ran for an hour without any problem, only then this error occured: Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your scripts and click the "Save Script" button and we'll attempt to start running them again. More info... For reference, the error message generated was: TypeError: Cannot read property '1' of null TypeError: Cannot read property '1' of null at apiscript.js:18892:44 at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:154:1), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:154:1), <anonymous>:70:8) at /home/node/d20-api-server/api.js:1648:12 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) at Id.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:489) at Zd.Ld.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:94:425) at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:111:400
1594212274
The Aaron
Roll20 Production Team
API Scripter
That's a great question without a great answer. You can often google for specific errors to try and understand what might cause it. In this case, there is some variable that the code expects to be an array, but which is actually the special value "null", which is being indexed by the value 1. Null is returned by some function to specify an "intentionally empty" value, as opposed to undefined, which is an "unintentionally empty" value. There is probably some rhyme or reason behind which ones do it, but it always feels a bit random. Regular expressions that don't match anything are a likely culprit.  You can also look at the call stack for where the issue happened. Often, there will be a function name that will hint at what code it was in. That's not the case here.  The last ditch thing you can do in these cases is look at this line: at apiscript.js:18892:44 This is telling you that the issue occurred in the 18,882nd line of the script, if you were to concatenation them all together from left to right.  If you want to do the math, you can get pretty neat the spot where the issue is. Hopefully that helps!
The Aaron said: The last ditch thing you can do in these cases is look at this line: at apiscript.js:18892:44 This is telling you that the issue occurred in the 18,882nd line of the script, if you were to concatenation them all together from left to right.  If you want to do the math, you can get pretty neat the spot where the issue is. Hopefully that helps! Thank you for your explanations. Might not help here, but in general certainly! These lines of scripts are all my lines (including those from the library)? I thought that this would include some code that runs on the server only. Anyway, how could I know, how many lines those scripts from the library have? Are they all available in the Github?
1594218922
Ada L.
Marketplace Creator
Sheet Author
API Scripter
Yes, those scripts are available in Github. It would really be helpful if scriptomancers took more care to wrap their code in try/catch blocks to capture and log any errors. The stack traces from logged errors contain much more useful information that makes it a lot easier to pinpoint these problems. In context to the immediate problem, I suppose that's neither here nor there...
1594222949
The Aaron
Roll20 Production Team
API Scripter
I should be better about that, probably.  I tend to not like try catch blocks for various reasons, and prefer writing code that is validated. But like you said, not germane to the topic. =D
One small idea for tracking down errors: One could deliberately put code into a script that will throw an exception / error. Now you have a line number you can probably work with .... this way you don't have to look for all coded lines in all scripts and count them :)