3

I'm currently getting an error that looks like this:

NoMethodError: undefined method `debug' for nil:NilClass
    /mnt/hgfs/Dropbox/Company/Project/lib/project/misc.rb:23:in `debug'
    /mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:49:in `block in compare_addresses'
    /mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:43:in `each'
    /mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:43:in `compare_addresses'
    /mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:32:in `valid?'
    /mnt/hgfs/Dropbox/Company/Project/specs/project/validation/google_geocoding_validation_engine_spec.rb:56:in `block (2 levels) in <module:Validation>'
    /home/tomas/ruby2/lib/ruby/2.0.0/minitest/unit.rb:1301:in `run'

I figured I'd try using byebug to figure out why the object is nil since it's never supposed to be nil. I placed byebug just above the erroneous line:

def debug(&block)
  if @logger.nil?
    byebug
  end

  @logger.debug(@logger_name, &block)
end

And ran the tests. I was dropped to the byebug debugging interface and could confirm that the object was indeed nil. The problem is that I can't climb up the stack:

(byebug) up
*** Adjusting would put us beyond the oldest (initial) frame.
(byebug) down
*** Adjusting would put us beyond the newest (innermost) frame.
(byebug) backtrace
--> #0  AddressKit::Misc::Logging.debug(block#Proc) at /mnt/hgfs/Dropbox/Kvantel/Address Kit/lib/addresskit/misc.rb:25
Warning: saved frames may be incomplete; compare with caller(0)

Why can't I go up the stack? Is this an issue with byebug or perhaps an incompatibility with MiniTest?

Hubro
  • 56,214
  • 69
  • 228
  • 381

1 Answers1

5

Answer for byebug >= 1.5.0

Printing and moving around the callstack in situations like this one should just work and the OP wouldn't have this issue.

Answer for byebug < 1.5.0 (also applicable to debugger or ruby-debug)

Byebug won't start tracking down callstack information until Byebug.start is called, which is internally called by the byebug command. So by the time you get the debugging prompt, only one callstack frame has been saved, that's why you get that message:

Warning: saved frames may be incomplete; compare with caller(0)

and that's why you can't move up or down: there's only one frame.

To properly navigate the stack, you need to start Byebug higher up, by dropping Byebug.start wherever you want to start tracking down callstack info. For example, before line 56 in google_geocoding_validation_engine_spec.rb. If you want full stack information, you can run byebug from the outset, by running the byebug executable:

byebug rake

or however you are running your specs.

If you still have issues, please let me know!

Hope this helps.

deivid
  • 4,808
  • 2
  • 33
  • 38
  • This worked, but now I get an error when trying to list the backtrace. In my case, when byebug tries to describe line #2 of the stack, it fails with the following text: "INTERNAL ERROR!!! no implicit conversion of nil into String". It fails in "byebug/processor.rb:78" in `initialize`. This means that any time I use the `backtrace` command or repeat the `up` command until I reach the specific stack frame, the debugger prints an error and resets to the deepest frame. Pretty annoying. I'm including this information since I got the impression you're a contributor (or the author) of `byebug`. – Hubro Jun 14 '13 at 22:03
  • Yes, I am. Could you please open an issue [here](https://github.com/deivid-rodriguez/byebug/issues/new)? Hopefully I can reproduce the error myself and fix it. Thanks! – deivid Jun 15 '13 at 01:37