Jul 112012
 

So let’s say you are, for example, upgrading your Rails app and when you boot it you get a crash with a mysterious “SystemStackError: stack level too deep” message. Problem is, you get no stacktrace on a stack level too deep. You know the problem is somewhere your your app’s boot-up, but you don’t know where.

My colleague found this little life-saver which I thought I’d document. Put this at the top of your application.rb and you’ll get ruby to print everything it requires as it loads your app, pinpointing exactly where the stack level too deep problem is.

module Kernel
 def require_and_print(string)
  puts string
  require_original(string)
 end
 alias_method :require_original, :require
 alias_method :require, :require_and_print
end