2

When I call Exception#backtrace_locations, it usually returns an array, as intended:

begin
  raise "foo"
rescue => e
  p e.backtrace_locations
end
# => ["this_file:2:in `<main>'"]

This is the same if I raise an ArgumentError manually:

begin
  raise ArgumentError.new
rescue => e
  p e.backtrace_locations
end
# => ["this_file:2:in `<main>'"]

However, when I raise a real ArgumentError by calling a method with wrong number of arguments, the backtrace_locations is nil, which is unexpected to me:

def foo; end

begin
  foo(:bar)
rescue => e
  p e.backtrace_locations
end
# => nil

Under the same situation, the classic Exception#backtrace returns an array, as intended:

def foo; end

begin
  foo(:bar)
rescue => e
  p e.backtrace
end
# => ["this_file:1:in `foo'", "this_file:4:in `<main>'"]

Is the return value of Exception#backtrace_locations being nil in the third case above intended? If so, when does Exception#backtrace_locations become nil? Is there any documentation for this? Or, is it a Ruby bug?

At this point, I think it is a bug, and reported it.

sawa
  • 165,429
  • 45
  • 277
  • 381
  • 1
    Looks like (if it's the same issue) it's not in 2.1 yet: https://bugs.ruby-lang.org/issues/8960 – CDub Dec 24 '13 at 19:08
  • @CDub What do you mean it's not in yet? Revision 44170 is supposed to have implemented it. And the method is returning `nil`; it is defined. If it is not defined, then it should rather raise an undefined error. – sawa Dec 24 '13 at 19:12
  • Per the last comment 12 days ago in the above thread: "Target version changed from current: 2.1.0 to next minor" ... I read that as "it will be in the next minor release, it's not in 2.1.0." – CDub Dec 24 '13 at 19:14
  • Or maybe I found the wrong issue... I'm open to being wrong. I've been wrong at least 131241 times today already. :) – CDub Dec 24 '13 at 19:15
  • 1
    @CDub Thanks for the comments. My interpretation of ko1's last comment on that thread is that he is done with `backtrace_locations`, but has not yet done `set_backtrace_locations` or the like. In that sense, it is half done, and has been set to the next minor. – sawa Dec 25 '13 at 06:54

1 Answers1

2

It was a bug, and the maintainer ko1 just fixed it in Revision 44411. Hopefully, it will make it into the release of Ruby 2.1 today.

Edit Turns out that it has not been fixed yet. Ruby 2.1 released today still has this issue.

Edit According to a maintainer, the fix will be incorporated into Ruby 2.1.1.

sawa
  • 165,429
  • 45
  • 277
  • 381