When cola.js fails, how do you find out what went wrong?
I don't have a minimal reproducible example, because that will likely take hours of debugging to make, and if I had it, then it wouldn't be an example of what I'm asking about. I'm hoping to hear of a way to quickly find out what's gone wrong. Presumably it's some bad data in my graph. But how can I tell what the bad data is?
The screenshot below illustrates a typical situation where something has gone wrong. Various NaNs are reported, there are a bunch of Uncaught TypeErrors, and an Assertion fails. There are a whole lot of local variables, all named with a single letter. Clicking and looking at them shows that a NaN got into a coordinate somewhere, as suggested by the previous error messages. It looks like sometime earlier, something got a null when it needed some sort of list-like data structure. How can I quickly find out what was the bad data that got into the graph?
I'm using cola.v3.min.js.
Details
I'm looking for a general approach to finding this kind of error, but here's the specific data that produced the errors in this example. Each line is the argument passed to cy.add() (as suggested by Stepan T.—and printing out everything passed to cy.add() might turn out to be the first step of the answer!).
{"group":"nodes","data":{"id":1,"label":"Workspace","parent":[]},"position":{"x":45,"y":0}}
{"group":"nodes","data":{"id":2,"label":"Target(121)","parent":[1]},"position":{"x":5,"y":0}}
{"group":"nodes","data":{"id":3,"label":"WantFullySourced","parent":[]},"position":{"x":50,"y":0}}
{"group":"nodes","data":{"id":4,"label":"Brick(120)","parent":[1]},"position":{"x":10,"y":0}}
{"group":"nodes","data":{"id":5,"label":"Avail","parent":[]},"position":{"x":55,"y":0}}
{"group":"nodes","data":{"id":6,"label":"Brick(1)","parent":[1]},"position":{"x":15,"y":0}}
{"group":"nodes","data":{"id":7,"label":"Avail","parent":[]},"position":{"x":60,"y":0}}
{"group":"nodes","data":{"id":8,"label":"Brick(2)","parent":[1]},"position":{"x":20,"y":0}}
{"group":"nodes","data":{"id":9,"label":"Avail","parent":[]},"position":{"x":65,"y":0}}
{"group":"nodes","data":{"id":10,"label":"Brick(3)","parent":[1]},"position":{"x":25,"y":0}}
{"group":"nodes","data":{"id":11,"label":"Avail","parent":[]},"position":{"x":70,"y":0}}
{"group":"nodes","data":{"id":12,"label":"Brick(4)","parent":[1]},"position":{"x":30,"y":0}}
{"group":"nodes","data":{"id":13,"label":"Avail","parent":[]},"position":{"x":75,"y":0}}
{"group":"nodes","data":{"id":14,"label":"Brick(5)","parent":[1]},"position":{"x":35,"y":0}}
{"group":"nodes","data":{"id":15,"label":"Avail","parent":[]},"position":{"x":80,"y":0}}
{"group":"nodes","data":{"id":16,"label":"NumericalRelationScout","parent":[1]},"position":{"x":40,"y":0}}
{"group":"nodes","data":{"id":17,"label":"OperandView","parent":[1]},"position":{"x":0,"y":0}}
{"group":"edges","data":{"id":"2.member_of.1.members","source":2,"source_port_label":"member_of","target":1,"target_port_label":"members","weight":0.5}}
{"group":"edges","data":{"id":"4.member_of.1.members","source":4,"source_port_label":"member_of","target":1,"target_port_label":"members","weight":0.5}}
{"group":"edges","data":{"id":"6.member_of.1.members","source":6,"source_port_label":"member_of","target":1,"target_port_label":"members","weight":0.5}}
{"group":"edges","data":{"id":"8.member_of.1.members","source":8,"source_port_label":"member_of","target":1,"target_port_label":"members","weight":0.5}}
{"group":"edges","data":{"id":"10.member_of.1.members","source":10,"source_port_label":"member_of","target":1,"target_port_label":"members","weight":0.5}}
{"group":"edges","data":{"id":"12.member_of.1.members","source":12,"source_port_label":"member_of","target":1,"target_port_label":"members","weight":0.5}}
{"group":"edges","data":{"id":"14.member_of.1.members","source":14,"source_port_label":"member_of","target":1,"target_port_label":"members","weight":0.5}}
{"group":"edges","data":{"id":"16.member_of.1.members","source":16,"source_port_label":"member_of","target":1,"target_port_label":"members","weight":0.5}}
{"group":"edges","data":{"id":"17.member_of.1.members","source":17,"source_port_label":"member_of","target":1,"target_port_label":"members","weight":0.5}}
{"group":"edges","data":{"id":"3.taggees.2.tags","source":3,"source_port_label":"taggees","target":2,"target_port_label":"tags","weight":0.5}}
{"group":"edges","data":{"id":"2.support_from.3.support_to","source":2,"source_port_label":"support_from","target":3,"target_port_label":"support_to","weight":2}}
{"group":"edges","data":{"id":"3.support_from.2.support_to","source":3,"source_port_label":"support_from","target":2,"target_port_label":"support_to","weight":2}}
{"group":"edges","data":{"id":"5.taggees.4.tags","source":5,"source_port_label":"taggees","target":4,"target_port_label":"tags","weight":0.5}}
{"group":"edges","data":{"id":"4.support_from.5.support_to","source":4,"source_port_label":"support_from","target":5,"target_port_label":"support_to","weight":2}}
{"group":"edges","data":{"id":"7.taggees.6.tags","source":7,"source_port_label":"taggees","target":6,"target_port_label":"tags","weight":0.5}}
{"group":"edges","data":{"id":"6.support_from.7.support_to","source":6,"source_port_label":"support_from","target":7,"target_port_label":"support_to","weight":2}}
{"group":"edges","data":{"id":"9.taggees.8.tags","source":9,"source_port_label":"taggees","target":8,"target_port_label":"tags","weight":0.5}}
{"group":"edges","data":{"id":"8.support_from.9.support_to","source":8,"source_port_label":"support_from","target":9,"target_port_label":"support_to","weight":2}}
{"group":"edges","data":{"id":"11.taggees.10.tags","source":11,"source_port_label":"taggees","target":10,"target_port_label":"tags","weight":0.5}}
{"group":"edges","data":{"id":"10.support_from.11.support_to","source":10,"source_port_label":"support_from","target":11,"target_port_label":"support_to","weight":2}}
{"group":"edges","data":{"id":"13.taggees.12.tags","source":13,"source_port_label":"taggees","target":12,"target_port_label":"tags","weight":0.5}}
{"group":"edges","data":{"id":"12.support_from.13.support_to","source":12,"source_port_label":"support_from","target":13,"target_port_label":"support_to","weight":2}}
{"group":"edges","data":{"id":"15.taggees.14.tags","source":15,"source_port_label":"taggees","target":14,"target_port_label":"tags","weight":0.5}}
{"group":"edges","data":{"id":"14.support_from.15.support_to","source":14,"source_port_label":"support_from","target":15,"target_port_label":"support_to","weight":2}}
The object passed to cy.layout() had a circular structure, so JSON.stringify() wouldn't print it. Adding the getCircularReplacer() function recommended here seemed to crash the browser. But manually removing elements from the layout object exposed the error: in a relative alignment constraint (documented under API here), I had an offset of '0' where I needed a 0, i.e. a string where a number was needed.
OK, happily that problem is now fixed. That still leaves the original question: is there a faster way to find errors like that? (The static-typing advocates are surely cackling by now.)
I'm downloading data from an online database using the imacros plugin for firefox. It works perfectly, except when the page times out. I've moved to downloading very small chunks of data since then the website times out much less frequently, but it still times out occasionally.
The problem is there's no way to code if statements directly into the imacros macro, so I wanted to have a greasemonkey script running along side it that will refresh the page if it timesout. The website only times out in one place for me, and when it does it shows the following:
can't open file
I never learned Java or Javascript and all of my programming experience deals with numerical methods, but I've been been piecing together code and adapting it to try and solve my problem.
The following is my base code:
var RefreshTime = '20';
var str1 = document.body.innerHTML
var str2 = "can't open file"
if (str1.search(str2) > 0) {
if (StRefTime > 0) setTimeout("location.reload(true);",RefreshTime*1000);
}
Since the browser I'm running this in is currently being used exclusively for this script I just have #include *
Basically what this is meant to do is refresh the page every 20 seconds as long "can't open file" is found the webpage. This works perfectly on other websites when I test it, but doesn't work at all on the website I need it to. It might be worth noting that when I refresh, firefox asks me to confirm resending post data - but imacros does have a function that I tested and works on this site to automatically confirm whenever the dialog is displayed.
After doing some reading I found that other people had similar problems, and I think the root of the cause is that if the page is arrived at through AJAX then greasemonkey misses it.
To address this I tried to implement the suggested solutions to those people, but I've been unsuccessful. For example I've tried putting the code I listed above into the solution given here: Run Greasemonkey script on the same page, multiple times? , for example
var RefreshTime = '20';
var str1 = document.body.innerHTML
var str2 = "can't open file"
function highlightGoodComments (jNode) {
//***** YOUR CODE HERE *****
if (/str2/i.test (jNode.text () ) ) {
if (str1.search(str2) > 0) {
if (RefreshTime > 0) setTimeout("location.reload(true);",RefreshTime*1000);
}
}
But this doesn't work either, and I've tried a couple variations of it (for example getting rid of str2 and just putting "open file" and things like that) and I've also tried and failed to make the following work https://gist.github.com/BrockA/2625891. I also tried wrapping all of my initial code in a setInterval loop with the hope that it would just check constantly for "can't open file" even without any page loading, but that didn't work either.
Unfortunately the website I'm running my script on is hidden behind a paywall, and it's hard to test my code since it times out somewhat randomly so there's no way to check if my code works outside of just waiting a long time and seeing if it failed. I know nothing about AJAX, so I'm not sure how to confirm that that is what's happening, but I still believe it to be so since my problem seemed similar to other people's - and when I enable this macro it does seem to interfere with other parts of the website but not the parts that my script works on.
I was hoping somebody could help me out, since I'm pretty stuck here and already in over my head. Even if you can't help, having some sort of AJAX website where I could test code without waiting several hours would be helpful to me trying to figure this out myself, if anybody knows of one. Thank you for reading through this, I really do appreciate any help anybody can offer.
The question is very long so I didn't bother to really read it. Since I don't use GreasMonkey I can tell you the iMacros solution.
Check if html element exists with iMacros and javascript
Here is a model how to built JS iMacros script and include if clause. You can make a testing macro that tests is t here "can't open" web page.
Also you can try to use
SET !TIMEOUT_PAGE 120
command to increase the time of page loading to 120 seconds. Try some of these if it can help.