views:

30

answers:

1

Using MRI 1.9

When an exception is raised that causes a backtrace to be printed, it would often be immensely easier to debug if the backtrace showed the receiver and values of method parameters as well as the method name. Is there any way of doing this?

Think about situations such as passing a nil deep into library code that wasn't expecting it, or where two strings have incompatible encodings and some routine is trying to concatenate them

+1  A: 

you can with 1.8.6 by using the backtracer gem.

1.9 has slightly broken callbacks so isn't compatible yet, though. I might be able to get it to work, if desired.

You could use something like a delegate and see the parameters to a single object:

class A
  def go a, b
  end
end

class A2

  def initialize *args
    @delegate = A.new *args
  end

  def method_missing meth, *args
    p "got call to #{meth}", args.join(', ')
    @delegate.send(meth,*args)
  end

end

which outputs

"in go2"
"got call to go"
"3, 4"
rogerdpack
I guess that "no"/"not yet" then that does at least constitute an answer, even if it's not the one I was hoping for ;-) When you say 1.9 has "broken callbacks" is that a design decision or just a bug that might someday be fixed?
telent
it's a bug, though there may be a work around...hmm...
rogerdpack