This is a common problem: you've got an infinite recursive loop going on somewhere.
Question is, how to deal with it as a developer. It's not always immediately obvious why it occurs.
After a few minutes of searching I came across this question
http://stackoverflow.com/questions/11544460/how-to-get-a-backtrace-from-a-systemstackerror-stack-level-too-deep
And one of the answers was to write something like
raise "crash me" if caller.length > 500caller is defined in Kernel, btw.This is very easy to do when you're debugging your scripts: figure out where the recursion is occurring, and then insert the line right before it.
For example, given the following code
def test1 test2enddef test2 test1endNow call `test1` or `test2` somewhere in your script.It is trivial, but you know there's a recursive loop and you're going to blow the stack eventually.
If you're printing the stacktrace to console using a script like cidiomar's full error backtrace, it will tell you which line basically blew the stack (I think), but it doesn't tell you anything else.
Ok so now we know line 2 was being visited frequently, so we use the trick above like this
def test1 raise "crash me" if caller.length > 20 test2 # this line was being called recursively repeatedly at some point # so let's interrupt it before ruby complainsenddef test2 test1endI set it to 20 because you shouldn't be calling test2 that many times anyways.Now when you run it, you'll see this in the console:
Now, whether you have any programming experience or not, you can look at the stacktrace and see that there's some repetition going on, and get a better idea where the problem is.
In my case, you can see that the two methods are just calling each other infinitely.
What kind of techniques do you use when it comes to SystemStackError debugging?
Question is, how to deal with it as a developer. It's not always immediately obvious why it occurs.
After a few minutes of searching I came across this question
http://stackoverflow.com/questions/11544460/how-to-get-a-backtrace-from-a-systemstackerror-stack-level-too-deep
And one of the answers was to write something like
raise "crash me" if caller.length > 500caller is defined in Kernel, btw.This is very easy to do when you're debugging your scripts: figure out where the recursion is occurring, and then insert the line right before it.
For example, given the following code
def test1 test2enddef test2 test1endNow call `test1` or `test2` somewhere in your script.It is trivial, but you know there's a recursive loop and you're going to blow the stack eventually.
If you're printing the stacktrace to console using a script like cidiomar's full error backtrace, it will tell you which line basically blew the stack (I think), but it doesn't tell you anything else.
Ok so now we know line 2 was being visited frequently, so we use the trick above like this
def test1 raise "crash me" if caller.length > 20 test2 # this line was being called recursively repeatedly at some point # so let's interrupt it before ruby complainsenddef test2 test1endI set it to 20 because you shouldn't be calling test2 that many times anyways.Now when you run it, you'll see this in the console:
Now, whether you have any programming experience or not, you can look at the stacktrace and see that there's some repetition going on, and get a better idea where the problem is.
In my case, you can see that the two methods are just calling each other infinitely.
What kind of techniques do you use when it comes to SystemStackError debugging?
Last edited by a moderator:

