troubleshooting warnings

7 views
Skip to first unread message

Chase A James

unread,
Feb 16, 2013, 10:47:55 AM2/16/13
to ky...@googlegroups.com
So I was getting a warning while running my specs (specifically "warning: Time#succ is obsolete; use time + 1"), but I didn't know what was causing it. It was printing the warning for every second in a time range =).

After doing some research, I learned that there isn't an obvious way to get the backtrace of a warning (i.e. make Ruby warnings fatal). I finally ended up hacking
activesupport-3.1.10/lib/active_support/time_with_zone.rb and added the line "puts caller.inspect if sym == :succ" to method_missing to get the calling methods and the line number. 

Kernel#caller gives you an array of every calling method, which is like a backtrace without throwing an exception.

Hope this was informative for any other rubyists missing some warnings and Kernel methods knowledge!

Todd Willey

unread,
Feb 16, 2013, 4:23:16 PM2/16/13
to ky...@googlegroups.com
Would it have worked to just reopen the class instead of editing your installed gems?  Something like:

class Time
  alias_method :original_succ, :succ
  def succ
    puts caller.inspect
    original_succ
  end
end

--
You received this message because you are subscribed to the Google Groups "Kentucky Ruby user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kyrug+un...@googlegroups.com.
To post to this group, send email to ky...@googlegroups.com.
Visit this group at http://groups.google.com/group/kyrug?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Chase A James

unread,
Feb 16, 2013, 4:28:04 PM2/16/13
to ky...@googlegroups.com
Yeah, that's much nicer. I probably could have just reopened Kernel.warn as well.
Reply all
Reply to author
Forward
0 new messages